2

When I run my aggregation using explain, as described here I get the following...

{ 
  "stages":[
      {
         "$cursor":{
              ...
              "planError":"InternalError No plan available to provide stats"
      }

Any thoughts on what is going on here? I really need to be able to see what (if any) index is being used in my $match stage.

Community
  • 1
  • 1
John B
  • 32,493
  • 6
  • 77
  • 98

4 Answers4

0

I tweaked your query just a bit (adding a match to the front since I don't want to unwind the Tags array for all document):

db.collection.aggregate(
  [ 
    { $match: {$or: [{"Tags._id":"tag1"},{"Tags._id":"tag2"}]}}, 
    { $unwind : "$Tags" }, 
    { $match: {$or: [{"Tags._id":"tag1"},{"Tags._id":"tag2"}]}}, 
    { $group: { _id : "$_id", count: { $sum:1 } }}, 
    {$sort: {"count":-1}}
  ],
  { explain: true }
)

And got:

{
    "stages" : [
        {
            "$cursor" : {
                "query" : {
                    "$or" : [
                        {
                            "Tags._id" : "tag1"
                        },
                        {
                            "Tags._id" : "tag2"
                        }
                    ]
                },
                "plan" : {
                    "cursor" : "BtreeCursor ",
                    "isMultiKey" : false,
                    "scanAndOrder" : false,
                    "indexBounds" : {
                        "Tags._id" : [
                            [
                                "tag1",
                                "tag1"
                            ],
                            [
                                "tag2",
                                "tag2"
                            ]
                        ]
                    },
                    "allPlans" : [
                        {
                            "cursor" : "BtreeCursor ",
                            "isMultiKey" : false,
                            "scanAndOrder" : false,
                            "indexBounds" : {
                                "Tags._id" : [
                                    [
                                        "tag1",
                                        "tag1"
                                    ],
                                    [
                                        "tag2",
                                        "tag2"
                                    ]
                                ]
                            }
                        }
                    ]
                }
            }
        },
        {
            "$unwind" : "$Tags"
        },
        {
            "$match" : {
                "$or" : [
                    {
                        "Tags._id" : "tag1"
                    },
                    {
                        "Tags._id" : "tag2"
                    }
                ]
            }
        },
        {
            "$group" : {
                "_id" : "$_id",
                "count" : {
                    "$sum" : {
                        "$const" : 1
                    }
                }
            }
        },
        {
            "$sort" : {
                "sortKey" : {
                    "count" : -1
                }
            }
        }
    ],
    "ok" : 1
}

While this doesn't quite address why your operation returns a planError, but maybe it can help some how.

Regards

Kay
  • 2,942
  • 18
  • 13
0

This seems to be a MongoDB 2.6 bug. Check the JIRA ticket.

Rafa Viotti
  • 9,998
  • 4
  • 42
  • 62
0

Had the same issue in my Rails app, fixed it by restarting rails server. MongoDB version is 2.6.4.

Andrii Furmanets
  • 1,081
  • 2
  • 12
  • 29
0

I worked around this by rebuilding all indexes on the collection. Not exactly elegant, but the error is gone now.

anthonyserious
  • 1,758
  • 17
  • 15