Twinsen
Twinsen

Reputation: 893

Explain Aggregate framework

I Just read this link Mongodb Explain for Aggregation framework but not explain my problem

I want retrieve information about aggregation like db.coll.find({bla:foo}).explain()

I tried

db.coll.aggregate([
        my-op
],
{
explain: true
}) 

the result is not Explain, but the query on Database.

I have tried also

db.runCommand({
        aggregate: "mycoll",
        pipeline: [
        my- op
        ],
        explain: true
    })

I retrieved information with this command, but i haven't millis, nscannedObjects etc...

I use mongoDb 2.6.2

Upvotes: 1

Views: 3679

Answers (2)

Salvador Dali
Salvador Dali

Reputation: 222581

I am not sure how you managed to fail getting explain information. In 2.6.x this information is available and you can explain your aggregation results:

db.orders.aggregate([
   # put your whole aggregation query
], {
   explain: true
})

which gives me something like:

{
    "stages" : [
        {
            "$cursor" : {
                "query" : {
                    "a" : 1
                },
                "queryPlanner" : {
                    "plannerVersion" : 1,
                    "namespace" : "test.a",
                    "indexFilterSet" : false,
                    "parsedQuery" : {
                        "a" : {
                            "$eq" : 1
                        }
                    },
                    "winningPlan" : {
                        "stage" : "COLLSCAN",
                        "filter" : {
                            "a" : {
                                "$eq" : 1
                            }
                        },
                        "direction" : "forward"
                    },
                    "rejectedPlans" : [ ]
                }
            }
        }
    ],
    "ok" : 1
}

Upvotes: 1

Ben
Ben

Reputation: 9895

Aggregations don't run like traditional queries and you can't run the explain on them. They are actually classified as commands and though they make use of indexes you can't readily find out how they are being executed in real-time.

Your best bet is to take the $match portion of your aggregation and run it as a query with explain to figure out how the indexes are performing and get an idea on nscanned.

Upvotes: 3

Related Questions