Are mongodb ids unique ?

How do I query mongodb with “like”?

SQL Server like used “%” operator but in mongodb used “.*” operator.

In the below example, I am looking for something that contains “ak” as string.

Query 1:   db.customers.find({"name": /.*ak.*/})
Query 2:  db.customers.find({"name": /ak/})

We can also use regex, the example look like below.

db.customers.find({ "name": { $regex: /ak/i } })
db.customers.find({"name": /^ak/})
db.customers.find({'name': {'$regex': 'ak'}})


Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog -
My Books - Book 1 and Book 2

How do I query mongodb with “like”? How do I query mongodb with “like”? Reviewed by Anil Singh on 5:39 AM Rating: (5) Powered by Blogger.