当我使用explain运行我的聚合时,如here所述,我得到以下内容......
{
"stages":[
{
"$cursor":{
...
"planError":"InternalError No plan available to provide stats"
}
关于这里发生了什么的任何想法?我真的需要能够看到我的$match
阶段中使用了什么(如果有的话)索引。
答案 0 :(得分:0)
我稍微调整了你的查询(在前面添加一个匹配项,因为我不想为所有文档展开Tags数组):
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 }
)
得到了:
{
"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
}
虽然这并不能完全解决为什么你的操作会返回一个planError,但也许它可以帮助你解决一些问题。
此致
答案 1 :(得分:0)
这似乎是一个MongoDB 2.6漏洞。检查the JIRA ticket。
答案 2 :(得分:0)
在我的Rails应用程序中遇到同样的问题,通过重启rails服务器修复它。 MongoDB版本是2.6.4。
答案 3 :(得分:0)
我通过重建集合上的所有索引来解决这个问题。不完全优雅,但现在错误消失了。