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

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

    For any one using Golang and wishes to have case sensitive full text search with mongodb and the mgo godoc globalsign library.

    collation := &mgo.Collation{
        Locale:   "en",
        Strength: 2, 
    }
    
    
    err := collection.Find(query).Collation(collation)
    

提交回复
热议问题