【发布时间】:2017-12-18 15:31:27
【问题描述】:
我有以下 8 亿个文档的 mongodb 文档。
Customer
{
"lastName" : "LAST",
"firstName" : "FIRST"
}
我有以下索引
db.customer.createIndex( {lastName: 1, firstName: 1},{collation: { locale: "en_US", strength: 1}})
如果我根据 lastName 和 firstName 进行搜索,那么它会很快并在 10 毫秒内得到结果。
db.customer.find({lastName:"LAST" ,firstName:"FIRST"}).collation({ locale: 'en_US', strength: 1 })
我正在尝试查找以“AS”作为姓氏字符的所有文档。但它需要超过 100 秒才能返回响应。我尝试了以下选项,但都花费了 100 多秒。
mongoDB真的不喜欢sql之类的操作吗('%AS%')
1)
db.customer.find({lastName:{"$regex": "AS"} ,firstName:"FIRST"}).collation({ locale: 'en_US', strength: 1 })
2)
db.customer.find({lastName:{"$regex": "/AS/"} ,firstName:"FIRST"}).collation({ locale: 'en_US', strength: 1 })
3)
db.customer.find({lastName:{"$regex": "^/AS/"} ,firstName:"FIRST"}).collation({ locale: 'en_US', strength: 1 })
【问题讨论】:
标签: mongodb mongodb-query