How do I make case-insensitive queries on Mongodb?

后端 未结 12 1195
北恋
北恋 2020-11-27 12:02
var thename = \'Andrew\';
db.collection.find({\'name\':thename});

How do I query case insensitive? I want to find result even if \"andrew\";

12条回答
  •  借酒劲吻你
    2020-11-27 12:14

    The following query will find the documents with required string insensitively and with global occurrence also

    db.collection.find({name:{
                                 $regex: new RegExp(thename, "ig")
                             }
                        },function(err, doc) {
                                             //Your code here...
                      });
    

提交回复
热议问题