我提出了一个问题,并试图在mongo控制台上解释它,然后得到了答案

"isMultiKey" : true,
"n" : 8,
"nscannedObjects" : 17272,
"nscanned" : 17272,
"nscannedObjectsAllPlans" : 21836,
"nscannedAllPlans" : 21836,
"scanAndOrder" : true,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 184,

大多数事情都在http://www.mongodb.org/display/DOCS/Explain中解释,但我不明白nscannedObjectsAllPlans,nscannedAllPlans是什么意思.有人能帮忙吗?

谢谢

推荐答案

nscannednscannedObjects为获胜的query plan人报告结果.

nscannedAllPlansnscannedObjectsAllPlans报告所有计划的结果.

Doc

扫描的索引项数.totalKeysExamined对应于MongoDB早期版本中cursor.explain()返回的nscanned字段.

例如:

t = db.jstests_explainb;
t.drop();

t.ensureIndex( { a:1, b:1 } );
t.ensureIndex( { b:1, a:1 } );

t.save( { a:0, b:1 } );
t.save( { a:1, b:0 } );

// Older mongodb (< 3.0? )
t.find( { a:{ $gte:0 }, b:{ $gte:0 } } ).explain( true );
    {
      "isMultiKey": false,
      "n": 2,
      "nscannedObjects": 2,
      "nscanned": 2,
      "nscannedObjectsAllPlans": 6,
      "nscannedAllPlans": 6,
      "scanAndOrder": false,
      "indexOnly": false,
      "nYields": 0,
      "nChunkSkips": 0,
      "millis": 2,
    ...
    }

// MongoDB 4.4
t.find( { a:{ $gte:0 }, b:{ $gte:0 } } ).explain( true );
{
    "queryPlanner" : {
        "plannerVersion" : 1,
        "namespace" : "test.jstests_explainb",
        ...
        "queryHash" : "CB67518C",
        "planCacheKey" : "5E76CDD1",
        "winningPlan" : {
            "stage" : "FETCH",
            "inputStage" : {
                "stage" : "IXSCAN",
                "keyPattern" : {
                    "a" : 1,
                    "b" : 1
                },
                "indexName" : "a_1_b_1",
            }
        },
        "rejectedPlans" : [
            {
                "stage" : "FETCH",
                "inputStage" : {
                    "stage" : "IXSCAN",
                    "keyPattern" : {
                        "b" : 1,
                        "a" : 1
                    },
                    "indexName" : "b_1_a_1",
                }
            }
        ],
        ...
    },
    "executionStats" : {
        "executionSuccess" : true,
        "nReturned" : 2,
        "executionTimeMillis" : 0,
        "totalKeysExamined" : 2, // <-- same as `nscanned`
        "totalDocsExamined" : 2, // <--
        "executionStages" : { ... }
        "allPlansExecution" : [
            {...},
            {...}
        ]
    }

Mongodb相关问答推荐

在MongoDB查询中添加来自另一个集合的匹配文档的计数

MongoDB/Mongoose查询:使用优先约束检索从位置A到位置B的路径

Select 筛选聚合中的嵌套字段

匹配/筛选/投影对象中数组中数组中的嵌套字段

优化游戏应用程序的反馈表单后端设计

随着时间的推移在 mongodb 中获得

MongoDB - 使用许多嵌套对象更新嵌套数组

MongoDB聚合 - 用另一个数组过滤数组

MongoDB PHP UTF-8 问题

mongo.lock 文件有什么用?

为什么 MongoDB 配置服务器必须只有一个或三个?

Mongoose $push 不断添加两个条目

使用 MongoDB C# 驱动程序在嵌套数组上使用过滤器生成器进行查询

将 JSON 与 MongoDB 一起使用?

如何根据其他字段添加条件模式?

当前的 URL 字符串解析器已弃用

从 id 删除 PyMongo 中的文档

MongoDB聚合将字符串数组连接到单个字符串

使用 mongoengine 将多文档插入到 mongodb

带有条件的MongoDB聚合查找