如果你像这样存储你的对象,Mongodb可以处理你想要的东西
{ score:2131, attributes: ["attr1", "attr2", "attr3"], ... }
Run Code Online (Sandbox Code Playgroud)
然后,以下查询将匹配具有att1和attr2的所有项目
c = db.mycol.find({ attributes: { $all: [ "attr1", "attr2" ] } })
Run Code Online (Sandbox Code Playgroud)
但这不符合它
c = db.mycol.find({ attributes: { $all: [ "attr1", "attr4" ] } })
Run Code Online (Sandbox Code Playgroud)
如果要对此游标进行排序,查询将返回一个游标,然后只需将排序参数添加到查询中
c = db.mycol.find({ attributes: { $all: [ "attr1", "attr2" ] }}).sort({score:1})
Run Code Online (Sandbox Code Playgroud)
查看高级查询以查看可能的内容.
可以如下设置适当的索引
db.mycol.ensureIndex({attributes:1, score:1})
Run Code Online (Sandbox Code Playgroud)
您可以使用获取性能信息
db.mycol.find({ attributes: { $all: [ "attr1" ] }}).explain()
Run Code Online (Sandbox Code Playgroud)
Mongo解释了扫描了多少对象,操作需要多长时间以及各种其他统计信息.
归档时间: |
|
查看次数: |
3889 次 |
最近记录: |