2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

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.

userimage

That would have to be:


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

or

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