How to query MongoDB with “like”?

后端 未结 30 2680
予麋鹿
予麋鹿 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:27

    Already u got the answers but to match regex with case insensitivity

    You could use the following query

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

    The i in the /m/i indicates case insensitivity and .pretty() provides a more pretty output

提交回复
热议问题