Reputation: 2049
I have to analyze the performance of a MongoDB query. I read I must use:
cursor.explain("executionStats")
So in my case, I used to analyze my query:
> db.team.find({common_name:"Milan"},{_id:0, "stadium.name":1}).explain("executionStats")
And this is the result:
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "Progettino.team",
"indexFilterSet" : false,
"parsedQuery" : {
"common_name" : {
"$eq" : "Milan"
}
},
"winningPlan" : {
"stage" : "PROJECTION",
"transformBy" : {
"_id" : 0,
"stadium.name" : 1
},
"inputStage" : {
"stage" : "COLLSCAN",
"filter" : {
"common_name" : {
"$eq" : "Milan"
}
},
"direction" : "forward"
}
},
"rejectedPlans" : [ ]
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 1,
"executionTimeMillis" : 0,
"totalKeysExamined" : 0,
"totalDocsExamined" : 87,
"executionStages" : {
"stage" : "PROJECTION",
"nReturned" : 1,
"executionTimeMillisEstimate" : 0,
"works" : 89,
"advanced" : 1,
"needTime" : 87,
"needFetch" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"transformBy" : {
"_id" : 0,
"stadium.name" : 1
},
"inputStage" : {
"stage" : "COLLSCAN",
"filter" : {
"common_name" : {
"$eq" : "Milan"
}
},
"nReturned" : 1,
"executionTimeMillisEstimate" : 0,
"works" : 89,
"advanced" : 1,
"needTime" : 87,
"needFetch" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"direction" : "forward",
"docsExamined" : 87
}
}
}
I want to know how long the query takes to be executed. I don't understand which is the the field containing this information.
Upvotes: 1
Views: 454
Reputation: 2636
The time your looking for is the executionTimeInMillis
however your query is only going over it looks like 87 documents so the execution time is extremely small.
Upvotes: 2