How to query MongoDB with "like" ?

Priya
Priya
Member
156 Points
43 Posts

I want to query something like SQL's like query:

SELECT * FROM nice-users  WHERE name LIKE '%n%'

How can I achieve the same in MongoDB? 

Views: 141
Total Answered: 1
Total Marked As Answer: 1
Posted On: 04-Aug-2021 23:18

Share:   fb twitter linkedin
Answers
edx
edx
110 Points
35 Posts
         

Use following query:

db.nice-users.find({"name": /.*n.*/})

Also, we can use regex as:

db.nice-users.find( { name : { $regex : .*n.* } } );
Posted On: 05-Aug-2021 21:12
Thanks.
 - Priya  18-Aug-2021 01:49
 Log In to Chat