|
I've created the following document for testing purposes:
{
|
"_id" : ObjectId("512b405b20ce3b931d06d9ed"),
|
"calls" : [
|
{
|
"ts" : 123456,
|
"n" : 100
|
},
|
{
|
"ts" : 123457,
|
"n" : 200
|
}
|
],
|
"query" : [
|
"shopId",
|
"clusterId",
|
"abc3"
|
]
|
}
|
Using the $all operator finds the document but does not return it:
shard01:PRIMARY> db.test.find( { query: { $all: [ "shopId", "clusterId", "abc3" ] } } )
|
Using $and however returns correctly the document (just to proof that it really exits):
shard01:PRIMARY> db.test.find( { $and: [ {query:"shopId"}, {query:"clusterId"}, {query:"abc3"} ] } )
|
{ "_id" : ObjectId("512b405b20ce3b931d06d9ed"), "calls" : [ { "ts" : 123456, "n" : 100 }, { "ts" : 123457, "n" : 200 } ], "query" : [ "shopId", "clusterId", "abc3" ] }
|
It seems that $all found the document since n is 1:
shard01:PRIMARY> db.test.find( { query: { $all: [ "shopId", "clusterId", "abc3" ] } } ).explain()
|
{
|
"cursor" : "BtreeCursor query_1",
|
"isMultiKey" : true,
|
"n" : 1,
|
"nscannedObjects" : 5,
|
"nscanned" : 5,
|
"nscannedObjectsAllPlans" : 5,
|
"nscannedAllPlans" : 5,
|
"scanAndOrder" : false,
|
"indexOnly" : false,
|
"nYields" : 0,
|
"nChunkSkips" : 0,
|
"millis" : 0,
|
"indexBounds" : {
|
"query" : [
|
[
|
"shopId",
|
"shopId"
|
]
|
]
|
},
|
"server" : "ws21109:27002"
|
}
|
However, find returns nothing and findOne returns null:
shard01:PRIMARY> db.test.findOne( { query: { $all: [ "shopId", "clusterId", "abc3" ] } } )
|
null
|
shard01:PRIMARY> db.test.find( { query: { $all: [ "shopId", "clusterId", "abc3" ] } } ).size()
|
1
|
shard01:PRIMARY> db.test.find( { query: { $all: [ "shopId", "clusterId", "abc3" ] } } ).count()
|
1
|
shard01:PRIMARY> db.test.find( { query: { $all: [ "shopId", "clusterId", "abc3" ] } } ).forEach(function(u){print(u)})
|
shard01:PRIMARY> db.test.find( { query: { $all: [ "shopId", "clusterId", "abc3" ] } } ).pretty()
|
However when I add .showDiskLoc, the document is shown correctly:
shard01:PRIMARY> db.test.find( { query: { $all: [ "shopId", "clusterId", "abc3" ] } } ).showDiskLoc()
|
{ "_id" : ObjectId("512b405b20ce3b931d06d9ed"), "calls" : [ { "ts" : 123456, "n" : 100 }, { "ts" : 123457, "n" : 200 } ], "query" : [ "shopId", "clusterId", "abc3" ], "$diskLoc" : { "file" : 0, "offset" : 7162144 } }
|
shard01:PRIMARY>
|
The same happens when queried through the java driver, hasNext will be false.
|