How to query MongoDB with “like” ?

How to query MongoDB with “like” ?

Asked on December 21, 2018 in MongoDB.
Add Comment

  • 1 Answer(s)

    That would have to be:

    db.users.find({“name”: /.*m.*/})
    or, similar:

    db.users.find({“name”: /m/})
    You’re looking for something that contains “m” somewhere (SQL’s ‘%’ operator is equivalent to Regexp’s ‘.*’), not something that has “m” anchored to the beginning of the string.

    Answered on February 4, 2019.
    Add Comment

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.