Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
2 views
in SQL by (20.3k points)

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

SELECT * FROM users  WHERE name LIKE '%m%'

How to do I achieve the same in MongoDB? I can't find an operator for like in the documentation.

1 Answer

+5 votes
by (40.7k points)
edited by

You can write it like this:

db.users.find({"name": /.*m.*/})

Are you interested in learning SQL from scratch! Have a look at this interesting video on SQL provided by Intellipaat:

or, like this code:

db.users.find({"name": /m/})

Basically, you are looking for something that includes “m” somewhere (i.e. ‘%’ operator of SQL is equivalent to Regexp’s’.*’), not something that contains “m” anchored to the beginning of string.

Related questions

0 votes
1 answer
asked Nov 21, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
0 votes
2 answers
asked Oct 16, 2019 in Web Technology by Sammy (47.6k points)
0 votes
1 answer

Browse Categories

...