Mongo Case不敏感索引(整理)没有得到结果

时间:2017-11-09 00:01:43

标签: mongodb indexing

我正在尝试使用Mongoid 5使用CaseInsensitive Index。我甚至去了Mongo控制台进行实验,但它根本不会得到结果:

> db.charges.getIndexes()
[
  {
    "v" : 1,
    "key" : {
      "_id" : 1
    },
    "name" : "_id_",
    "ns" : "paymentsapi_development.charges"
  }
]
> db.charges.createIndex({'details.email':1},{name:'emails_index',collation:{locale:'en',strength:1}})
{
  "createdCollectionAutomatically" : false,
  "numIndexesBefore" : 1,
  "numIndexesAfter" : 2,
  "ok" : 1
}
> db.charges.getIndexes()
[
  {
    "v" : 1,
    "key" : {
      "_id" : 1
    },
    "name" : "_id_",
    "ns" : "paymentsapi_development.charges"
  },
  {
    "v" : 1,
    "key" : {
      "details.email" : 1
    },
    "name" : "emails_index",
    "ns" : "paymentsapi_development.charges",
    "collation" : {
      "locale" : "en",
      "strength" : 1
    }
  }
]
> db.charges.find({'details.email':'lolo@lolo.com'}).count()
1
> db.charges.find({'details.email':'LoLo@LoLo.cOm'}).collation({locale:'en',strength:1}).count()
0
>

我基于排序规则(https://docs.mongodb.com/manual/reference/collation/)和不区分大小写的索引(https://docs.mongodb.com/manual/core/index-case-insensitive/)。

我已经检查了db版本,基于https://docs.mongodb.com/manual/reference/command/setFeatureCompatibilityVersion/db.adminCommand( { setFeatureCompatibilityVersion: <version> } )以及所有可能的更多内容。

非常感谢任何帮助。

0 个答案:

没有答案