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

后端 未结 24 1866
谎友^
谎友^ 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:30

    As you can see in mongo docs - since version 3.2 $text index is case-insensitive by default: https://docs.mongodb.com/manual/core/index-text/#text-index-case-insensitivity

    Create a text index and use $text operator in your query.

提交回复
热议问题