Chapter 2: MongoDB Indexes, winningPlan.stage, shar0 missing in getShardDistribution()

Hello everyone, here is my shard status

--- Sharding Status ---
  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,
        "currentVersion" : 6,
        "clusterId" : ObjectId("60c7648248f592915c6585dd")
  }
  shards:
        {  "_id" : "shard01",  "host" : "shard01/localhost:27018,localhost:27019,localhost:27020",  "state" : 1 }
        {  "_id" : "shard02",  "host" : "shard02/localhost:27021,localhost:27022,localhost:27023",  "state" : 1 }
  active mongoses:
        "4.4.4" : 1
  autosplit:
        Currently enabled: yes
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours:
                512 : Success
  databases:
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }
                config.system.sessions
                        shard key: { "_id" : 1 }
                        unique: false
                        balancing: true
                        chunks:
                                shard01 512
                                shard02 512
                        too many chunks to print, use verbose if you want to force print
        {  "_id" : "m201",  "primary" : "shard02",  "partitioned" : true,  "version" : {  "uuid" : UUID("39c3bea8-76cb-4a9a-a7ba-019558793f78"),  "lastMod" : 1 } }
                m201.people
                        shard key: { "_id" : 1 }
                        unique: false
                        balancing: true
                        chunks:
                                shard02 1
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard02 Timestamp(1, 0)

I could not get the shard0 when we shard on the people collections.
db.people.getShardDistribution()
here is the output, I’m not sure why?

Shard shard02 at shard02/localhost:27021,localhost:27022,localhost:27023
 data : 18.66MiB docs : 50474 chunks : 1
 estimated data per chunk : 18.66MiB
 estimated docs per chunk : 50474

Totals
 data : 18.66MiB docs : 50474 chunks : 1
 Shard shard02 contains 100% data, 100% docs in cluster, avg obj size on shard : 387B

Here is the “executionStats” of people collection

{
        "queryPlanner" : {
                "mongosPlannerVersion" : 1,
                "winningPlan" : {
                        "stage" : "SINGLE_SHARD",
                        "shards" : [
                                {
                                        "shardName" : "shard02",
                                        "connectionString" : "shard02/localhost:27021,localhost:27022,localhost:27023",
                                        "serverInfo" : {
                                                "host" : "LAPTOP-6UC55ONM",
                                                "port" : 27021,
                                                "version" : "4.4.4",
                                                "gitVersion" : "8db30a63db1a9d84bdcad0c83369623f708e0397"
                                        },
                                        "plannerVersion" : 1,
                                        "namespace" : "m201.people",
                                        "indexFilterSet" : false,
                                        "parsedQuery" : {
                                                "$and" : [
                                                        {
                                                                "address.state" : {
                                                                        "$eq" : "New York"
                                                                }
                                                        },
                                                        {
                                                                "last_name" : {
                                                                        "$eq" : "Johnson"
                                                                }
                                                        }
                                                ]
                                        },
                                        "winningPlan" : {
                                                "stage" : "SHARDING_FILTER",
                                                "inputStage" : {
                                                        "stage" : "COLLSCAN",
                                                        "filter" : {
                                                                "$and" : [
                                                                        {
                                                                                "address.state" : {

        "$eq" : "New York"
                                                                                }
                                                                        },
                                                                        {
                                                                                "last_name" : {

        "$eq" : "Johnson"
                                                                                }
                                                                        }
                                                                ]
                                                        },
                                                        "direction" : "forward"
                                                }
                                        },
                                        "rejectedPlans" : [ ]
                                }
                        ]
                }
        },
        "executionStats" : {
                "nReturned" : 7,
                "executionTimeMillis" : 45,
                "totalKeysExamined" : 0,
                "totalDocsExamined" : 50474,
                "executionStages" : {
                        "stage" : "SINGLE_SHARD",
                        "nReturned" : 7,
                        "executionTimeMillis" : 45,
                        "totalKeysExamined" : 0,
                        "totalDocsExamined" : 50474,
                        "totalChildMillis" : NumberLong(44),
                        "shards" : [
                                {
                                        "shardName" : "shard02",
                                        "executionSuccess" : true,
                                        "nReturned" : 7,
                                        "executionTimeMillis" : 44,
                                        "totalKeysExamined" : 0,
                                        "totalDocsExamined" : 50474,
                                        "executionStages" : {
                                                "stage" : "SHARDING_FILTER",
                                                "nReturned" : 7,
                                                "executionTimeMillisEstimate" : 4,
                                                "works" : 50476,
                                                "advanced" : 7,
                                                "needTime" : 50468,
                                                "needYield" : 0,
                                                "saveState" : 50,
                                                "restoreState" : 50,
                                                "isEOF" : 1,
                                                "chunkSkips" : 0,
                                                "inputStage" : {
                                                        "stage" : "COLLSCAN",
                                                        "filter" : {
                                                                "$and" : [
                                                                        {
                                                                                "address.state" : {

        "$eq" : "New York"
                                                                                }
                                                                        },
                                                                        {
                                                                                "last_name" : {

        "$eq" : "Johnson"
                                                                                }
                                                                        }
                                                                ]
                                                        },
                                                        "nReturned" : 7,
                                                        "executionTimeMillisEstimate" : 4,
                                                        "works" : 50476,
                                                        "advanced" : 7,
                                                        "needTime" : 50468,
                                                        "needYield" : 0,
                                                        "saveState" : 50,
                                                        "restoreState" : 50,
                                                        "isEOF" : 1,
                                                        "direction" : "forward",
                                                        "docsExamined" : 50474
                                                }
                                        }
                                }
                        ]
                }
        },
        "serverInfo" : {
                "host" : "LAPTOP-6UC55ONM",
                "port" : 27017,
                "version" : "4.4.4",
                "gitVersion" : "8db30a63db1a9d84bdcad0c83369623f708e0397"
        },
        "ok" : 1,
        "operationTime" : Timestamp(1623681702, 1),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1623681708, 3),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        }
}

In the “winningPlan.stage” I see the value is SINGLE_SHARD, but in the video, It’s SHARD_MERGE .

Is it because of less data or am I doing wrong somewhere?

Yes
Try it on a bigger collection like products. Understanding Explain for Sharded Clusters : people collection is shared on one shard only

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.