db.tablebusiness.find({ "LongitudeLatitude" : { "$nearSphere" : [106.772835, -6.186753], "$maxDistance" : 0.053980478460939611 }, "Prominent" : { "$gte" : 15 }, "indexContents" : { "$all" : [/^soto/, /^nasi/] } }).limit(200);
db.tablebusiness.find({ "LongitudeLatitude" : { "$nearSphere" : [106.772835, -6.186753], "$maxDistance" : 0.053980478460939611 }, "Prominent" : { "$gte" : 15 }, "indexContents" : { "$in" : [/^soto/, /^nasi/] } }).limit(200);这就是结果
/* 88 */
{
"ts" : ISODate("2012-09-11T06:57:26.801Z"),
"op" : "query",
"ns" : "newisikota.tablebusiness",
"query" : {
"LongitudeLatitude" : {
"$nearSphere" : [106.772835, -6.186753],
"$maxDistance" : 0.053980478460939611
},
"Prominent" : {
"$gte" : 15.0
},
"indexContents" : {
"$all" : [/^soto/, /^nasi/]
}
},
"ntoreturn" : 200,
"nscanned" : 48,
"nreturned" : 48,
"responseLength" : 60002,
"millis" : 3821,
"client" : "127.0.0.1",
"user" : ""
}
/* 89 */
{
"ts" : ISODate("2012-09-11T06:57:43.147Z"),
"op" : "query",
"ns" : "newisikota.tablebusiness",
"query" : {
"LongitudeLatitude" : {
"$nearSphere" : [106.772835, -6.186753],
"$maxDistance" : 0.053980478460939611
},
"Prominent" : {
"$gte" : 15.0
},
"indexContents" : {
"$in" : [/^soto/, /^nasi/]
}
},
"ntoreturn" : 200,
"nscanned" : 200,
"nreturned" : 200,
"responseLength" : 249598,
"millis" : 320,
"client" : "127.0.0.1",
"user" : ""
}注意:$all查询可以偶尔运行26秒。
解释结果如下:
db.tablebusiness.find({ "LongitudeLatitude" : { "$nearSphere" : [106.772835, -6.186753], "$maxDistance" : 0.053980478460939611 }, "Prominent" : { "$gte" : 15 }, "indexContents" : { "$all" : [/^soto/, /^nasi/] } }).limit(200).explain();
{
"cursor" : "GeoSearchCursor",
"nscanned" : 48,
**"nscannedObjects" : 48,**
"n" : 48,
"millis" : 8563,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
}
}
>
db.tablebusiness.find({ "LongitudeLatitude" : { "$nearSphere" : [106.772835, -6.186753], "$maxDistance" : 0.053980478460939611 }, "Prominent" : { "$gte" : 15 }, "indexContents" : { "$in" : [/^soto/, /^nasi/] } }).limit(200).explain();
{
"cursor" : "GeoSearchCursor",
"nscanned" : 200,
**"nscannedObjects" : 200,**
"n" : 200,
"millis" : 516,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
}
}请注意,$in search scan more对象。
在最坏的情况下,mongdob可以做$in搜索,然后过滤掉。这个比率不应该很大。
发布于 2012-09-24 23:07:33
我在Why using $all in mongodb is much slower?中问了一个类似的问题。
这一次我只用了一个词。因此,$in和$all之间应该没有区别。它们都是等价的。
尽管如此,$all的速度还是要慢得多。
事实证明,根据这个问题的答案,mongodb本身存在一个bug。
https://jira.mongodb.org/browse/SERVER-1748
我想,在问题解决之前,我根本不会使用$all。
对于所有其他答案,你自己试过了吗?
发布于 2012-09-11 16:59:46
你在拿苹果和桔子作比较。这两个查询返回不同的结果。$all表示字段值应与所有输入匹配,而$in表示字段值应与其中任何一个值匹配。$all是and,$in是or。
与$limit结合使用-与中相比,$all查询将需要查看更多文档来查找匹配项。
https://stackoverflow.com/questions/12364377
复制相似问题