Like in MongoDB Query

In SQL, 'LIKE' query look like as below

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

In MongoDB it's look 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

PostgreSQL-Query: Sort result set by specific field values using ORDER BY Clause

Problem: Suppose we have a book_inventory table which has some columns such as id, isbn, title, author, publisher, publish_date, etc.. whe...