How to query MongoDB with “like”?

后端 未结 30 2075
予麋鹿
予麋鹿 2020-11-21 05:51

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

30条回答
  •  日久生厌
    2020-11-21 06:20

    If you want 'Like' search in mongo then you should go with $regex by using this query will be

    db.product.find({name:{$regex:/m/i}})

    for more you can read the documentation as well. https://docs.mongodb.com/manual/reference/operator/query/regex/

提交回复
热议问题