How to get document _id and other information

Fellows, after running exp.find({ssn: “720-38-5636”}) , where is document _id ? How do i know in which document was it found ?

Are you running an explain plan on the collection?

Yes, result below:
“queryPlanner” : {
“plannerVersion” : 1,
“namespace” : “m201.people”,
“indexFilterSet” : false,
“parsedQuery” : {
“ssn” : {
“$eq” : “720-38-5636”
}
},
“queryHash” : “9CB07BBF”,
“planCacheKey” : “166A13B8”,
“winningPlan” : {
“stage” : “FETCH”,
“inputStage” : {
“stage” : “IXSCAN”,
“keyPattern” : {
“ssn” : 1
},
“indexName” : “ssn_1”,
“isMultiKey” : false,
“multiKeyPaths” : {
“ssn” :
},
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 2,
“direction” : “forward”,
“indexBounds” : {
“ssn” : [
“[“720-38-5636”, “720-38-5636”]”
]
}
}
},
“rejectedPlans” :
},
“executionStats” : {
“executionSuccess” : true,
“nReturned” : 1,
“executionTimeMillis” : 0,
“totalKeysExamined” : 1,
“totalDocsExamined” : 1,
“executionStages” : {
“stage” : “FETCH”,
“nReturned” : 1,
“executionTimeMillisEstimate” : 0,
“works” : 2,
“advanced” : 1,
“needTime” : 0,
“needYield” : 0,
“saveState” : 0,
“restoreState” : 0,
“isEOF” : 1,
“docsExamined” : 1,
“alreadyHasObj” : 0,
“inputStage” : {
“stage” : “IXSCAN”,
“nReturned” : 1,
“executionTimeMillisEstimate” : 0,
“works” : 2,
“advanced” : 1,
“needTime” : 0,
“needYield” : 0,
“saveState” : 0,
“restoreState” : 0,
“isEOF” : 1,
“keyPattern” : {
“ssn” : 1
},
“indexName” : “ssn_1”,
“isMultiKey” : false,
“multiKeyPaths” : {
“ssn” :
},
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 2,
“direction” : “forward”,
“indexBounds” : {
“ssn” : [
“[“720-38-5636”, “720-38-5636”]”
]
},
“keysExamined” : 1,
“seeks” : 1,
“dupsTested” : 0,
“dupsDropped” : 0
}
}
},

}

explain doesn’t show you the _id field or values. Run a normal find() on the collection if you want to find the _id.

I get it, and it will use index for specific indexed field.

Yes, that’s what it will do when you run db.collection.find().
explain will show you which index it will use based on the filter you enter in find(). If your filter doesn’t use _id then it will not use the _id index.

Hi @artur_o,

As mentioned by @007_jb, running the query with explain method will return a document with the query plan and execution statistics.

Please refer to the following documentation on details about explain method:

Please let me know, if you have any questions.

Thanks,
Sonali