分析查询的性能 - mongoDB

时间:2015-08-02 19:51:25

标签: mongodb nosql

我必须分析MongoDB查询的性能。我读过我必须使用:

cursor.explain("executionStats")

所以在我的情况下,我曾经分析过我的查询:

> db.team.find({common_name:"Milan"},{_id:0, "stadium.name":1}).explain("executionStats")

这就是结果:

{
        "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
                        }
                }
        }

我想知道执行查询需要多长时间。我不明白哪个是包含此信息的字段。

1 个答案:

答案 0 :(得分:2)

您查找的时间是executionTimeInMillis,但是您的查询只会超过它看起来像87个文档,因此执行时间非常短。

相关问题