How to query MongoDB with “like”?

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

    You can use where statement to build any JS script:

    db.myCollection.find( { $where: "this.name.toLowerCase().indexOf('m') >= 0" } );
    

    Reference: http://docs.mongodb.org/manual/reference/operator/where/

提交回复
热议问题