-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 3.0.6, 3.0.7
-
Component/s: Querying
-
None
-
ALL
Hi!
I have noticed that MongoDB won't use indexes when querying for a distinct value on a field. I will use it on some fields, but won't on others.
Here's the example:
db.product.createIndex({"_indexed.preventieve_mondzorg-max_bedrag_p_jr": 1}); db.runCommand({distinct: "product", key:"_indexed.preventieve_mondzorg-max_bedrag_p_jr"});
And that's what it produces:
{ "createdCollectionAutomatically" : false, "numIndexesBefore" : 50, "numIndexesAfter" : 50, "note" : "all indexes already exist", "ok" : 1 } { "values" : [ "€ 250,- | 75%", "Geen dekking", "...", ], "stats" : { "n" : 33660, "nscanned" : 0, "nscannedObjects" : 33660, "timems" : 12531, "planSummary" : "COLLSCAN" }, "ok" : 1 }
On the other hand
db.product.createIndex({"free_choice.value": 1}); db.runCommand({distinct: "product", key:"free_choice.value"});
Will the index:
{ "createdCollectionAutomatically" : false, "numIndexesBefore" : 50, "numIndexesAfter" : 50, "note" : "all indexes already exist", "ok" : 1 } { "values" : [ "gedeeltelijk", "geen", "ja" ], "stats" : { "n" : 4, "nscanned" : 4, "nscannedObjects" : 4, "timems" : 2, "planSummary" : "DISTINCT { free_choice.value: 1.0 }" }, "ok" : 1 }
So... what could be the difference between those two fields?
Is it a bug, or I am doing something wrong?
- duplicates
-
SERVER-13298 distinct doesn't use index to distinct multikey dotted fields
- Closed