How to query MongoDB with “like”?

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

    If using node.js, it says that you can write this:

    db.collection.find( { field: /acme.*corp/i } );
    //or
    db.collection.find( { field: { $regex: 'acme.*corp', $options: 'i' } } );
    

    Also, you can write this:

    db.collection.find( { field: new RegExp('acme.*corp', 'i') } );
    

提交回复
热议问题