MongoDB: Is it possible to make a case-insensitive query?

后端 未结 24 2132
谎友^
谎友^ 2020-11-22 04:44

Example:

> db.stuff.save({\"foo\":\"bar\"});

> db.stuff.find({\"foo\":\"bar\"}).count();
1
> db.stuff.find({\"foo\":\"BAR\"}).count();
0

24条回答
  •  日久生厌
    2020-11-22 05:23

    Use RegExp, In case if any other options do not work for you, RegExp is a good option. It makes the string case insensitive.

    var username = new RegExp("^" + "John" + "$", "i");;
    

    use username in queries, and then its done.

    I hope it will work for you too. All the Best.

提交回复
热议问题