Hi @Tomaz_Beltram and welcome back !
Looks like you are trying to make a covered query.
Can you please confirm which indexes exist in this collection?
If you really want to know what mongod
is doing to resolve your query, you can use explain. If you have a covered query, then you won’t see a FETCH stage in your winning plan.
To make this query db.myobjects.find({},{"indexed_attributes":1})
covered, you would need to have the index {'indexed_attributes': 1, '_id': 1}
because you are returning both these values here as ‘_id’ is present by default and needs to be explicitly removed in the projection if you don’t want it. But if you do return it, it needs to be in your index to make it a covered query. You will probably also need to add a filter using your index in the query to trigger the use of the index.
This example is a bit silly but…
db.coll.find({b: 1},{b: 1, _id:0}).explain()
This is what it should look like in the explain plan:
"winningPlan" : {
"stage" : "PROJECTION_COVERED",
"transformBy" : {
"b" : 1,
"_id" : 0
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"b" : 1,
"_id" : 1
},
"indexName" : "b_1__id_1",
"isMultiKey" : false,
"multiKeyPaths" : {
"b" : [ ],
"_id" : [ ]
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"b" : [
"[1.0, 1.0]"
],
"_id" : [
"[MinKey, MaxKey]"
]
}
}
I hope this helps.
Cheers,
Maxime.