MongoDB v4 explain() doesn't return number of scanned docs (unlike the previous version). How to be?

34 views Asked by At

I am reading the book "MongoDB in Action" and there is an example of the explain() method.

Shell command: db.values.find({}).sort({close: -1}).limit(1).explain()

Result:

db.values.find({}).sort({close: -1}).limit(1).explain()
{
 "cursor" : "BasicCursor",
 "isMultiKey" : false,
 "n" : 1,
 "nscannedObjects" : 4308303,
 "nscanned" : 4308303,
 "nscannedObjectsAllPlans" : 4308303,
 "nscannedAllPlans" : 4308303,
 "scanAndOrder" : true,
 "indexOnly" : false,
 "nYields" : 4,
 "nChunkSkips" : 0,
 "millis" : 10927,
 "indexBounds" : { },
 "server" : "localhost:27017"
}

I've tried it on my shell and got the result below:

{
"queryPlanner" : {
    "plannerVersion" : 1,
    "namespace" : "storks.values",
    "indexFilterSet" : false,
    "parsedQuery" : {
        
    },
    "winningPlan" : {
        "stage" : "SORT",
        "sortPattern" : {
            "close" : -1
        },
        "limitAmount" : 1,
        "inputStage" : {
            "stage" : "SORT_KEY_GENERATOR",
            "inputStage" : {
                "stage" : "COLLSCAN",
                "direction" : "forward"
            }
        }
    },
    "rejectedPlans" : [ ]
},
"serverInfo" : {
    "host" : "user-System-Product-Name",
    "port" : 27017,
    "version" : "4.0.3",
    "gitVersion" : "7ea530946fa7880364d88c8d8b6026bbc9ffa48c"
},
"ok" : 1

}

My Mongo version number exeeds the books one (I am using v4).

I am curious how can I get the info about the scanned docs in MongoDB v4?

And why is this data is not supplied by explain() anymore? Is this not relevant anymore or got some replacement?

0

There are 0 answers