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

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

    These have been tested for string searches

    {'_id': /.*CM.*/}               ||find _id where _id contains   ->CM
    {'_id': /^CM/}                  ||find _id where _id starts     ->CM
    {'_id': /CM$/}                  ||find _id where _id ends       ->CM
    
    {'_id': /.*UcM075237.*/i}       ||find _id where _id contains   ->UcM075237, ignore upper/lower case
    {'_id': /^UcM075237/i}          ||find _id where _id starts     ->UcM075237, ignore upper/lower case
    {'_id': /UcM075237$/i}          ||find _id where _id ends       ->UcM075237, ignore upper/lower case
    

提交回复
热议问题