Like in MongoDB Query


If you are familiar with SQL Server or another relation database, the  'LIKE' query look like as below.

SELECT * FROM [dbo.][USERS] WHERE FNAME LIKE '%DILIP%'

In MongoDB, it looks like as below(query in MongoDB console)

db.USERS.find({"FNAME":/DILIP/})

Same as

db.USERS.find({"FNAME":/^DILIP/})   // FNAME LIKE 'DILIP%'

db.USERS.find({"FNAME":/DILIP$/})   // FNAME LIKE '%DILIP'

$regex in MongoDB

No comments:

Post a Comment

Please do not enter any spam link in the comment box.

Related Posts

What is the Use of isNaN Function in JavaScript? A Comprehensive Explanation for Effective Input Validation

In the world of JavaScript, input validation is a critical aspect of ensuring that user-provided data is processed correctly. One indispensa...