I am well aware of what those 2 do. $in take .3 seconds. And $all take 26 seconds. Huge different. If anything $in should take longer because it returns more data.
Also if the limit is removed, $in actually is much faster.
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);
This is result
/* 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" : ""
}
Note: the $all query can run for 26 seconds once in a while.
The explain result is the following:
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" : {
}
}
Notice that the $in search scan more object.