performance - Mongodb query using $and operator does full scan while same query without doesn't -
i'm relatively new mongodb , i'm having trouble understanding why query $and operator seems full scan, while same query without doesn't.
my document looks this
{_id:"123456", labels : [{label:"beef", language:"en"}, {...}],...}
i have compound index on label , language, however, explain shows different results depending on whether do
db.mycollection.find({ "labels" : { "$elemmatch" : { "label" : "beef" , "$and" : [ { "lang" : "en"}]}}}).explain() { "cursor" : "complex plan", "n" : 4, "nscannedobjects" : 0, "nscanned" : 16701573, "nscannedobjectsallplans" : 0, "nscannedallplans" : 16701573, "nyields" : 130540, "nchunkskips" : 0, "millis" : 16283, "filterset" : false }
or
db.mycollection.find({ "labels" : {$elemmatch: { label:"beef" ,"lang" : "en" }}}).explain() { "cursor" : "btreecursor labels.label_1_labels.lang_1", "ismultikey" : true, "n" : 4, "nscannedobjects" : 4, "nscanned" : 4, "nscannedobjectsallplans" : 4, "nscannedallplans" : 4, "scanandorder" : false, "indexonly" : false, "nyields" : 0, "nchunkskips" : 0, "millis" : 0, "indexbounds" : { "labels.label" : [ [ "beef", "beef" ] ], "labels.lang" : [ [ "en", "en" ] ] }, "filterset" : false }
can me understand why?.
thanks in advance!.
Comments
Post a Comment