獲取一個 MongoDB 集合中的執行統計資訊
要在 MongoDB 中獲取統計資訊,可以使用 explain() 方法。讓我們建立一個包含文件的集合 −
> db.demo157.insertOne({"Status":"Active"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e354fdffdf09dd6d08539fc")
}
> db.demo157.insertOne({"Status":"InActive"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e354fe3fdf09dd6d08539fd")
}使用 find() 方法顯示一個集合中所有文件 −
> db.demo157.find();
這將產生以下輸出 −
{ "_id" : ObjectId("5e354fdffdf09dd6d08539fc"), "Status" : "Active" }
{ "_id" : ObjectId("5e354fe3fdf09dd6d08539fd"), "Status" : "InActive" }以下是如何在 MongoDB 中實現 explain() 方法 −
> db.demo157.find({Status: { $in: ['Active','InActive'] }}).explain("executionStats");這將產生以下輸出 −
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "test.demo157",
"indexFilterSet" : false,
"parsedQuery" : {
"Status" : {
"$in" : [
"Active",
"InActive"
]
}
},
"winningPlan" : {
"stage" : "COLLSCAN",
"filter" : {
"Status" : {
"$in" : [
"Active",
"InActive"
]
}
},
"direction" : "forward"
},
"rejectedPlans" : [ ]
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 2,
"executionTimeMillis" : 18,
"totalKeysExamined" : 0,
"totalDocsExamined" : 2,
"executionStages" : {
"stage" : "COLLSCAN",
"filter" : {
"Status" : {
"$in" : [
"Active",
"InActive"
]
}
},
"nReturned" : 2,
"executionTimeMillisEstimate" : 0,
"works" : 4,
"advanced" : 2,
"needTime" : 1,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"direction" : "forward",
"docsExamined" : 2
}
},
"serverInfo" : {
"host" : "DESKTOP-QN2RB3H",
"port" : 27017,
"version" : "4.0.5",
"gitVersion"
"3739429dd92b92d1b0ab120911a23d50bf03c412"
},
"ok" : 1
}
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP