2017  Kodetalk | Feedback | Privacy Policy | Terms | About

How to query mongodb with “like”?

I want query something as SQL"s like:

select * from users where name like "%m%"How to do the same in mongodb?

I can"t find a operator for like in the documentation.


That would have to be:

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


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

You're looking for something that contains "m" somewhere (SQL's '%' operator is equivalent to regexps' '.*'), not something that has "m" anchored to the beginning of the string.

Answer is