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'}})


Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
Post a Comment Powered by Blogger.
ASK Questions