+2 votes
1 view
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.3k 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
0 votes
2 answers
asked Oct 16, 2019 in Web Technology by Sammy (47.8k points)
0 votes
1 answer
0 votes
2 answers
Welcome to Intellipaat Community. Get your technical queries answered by top developers !