db.userData.aggregate({
$group : { "_id" : "$user.id",
"count": { "$sum":1 },
"ids": { "$push": "$_id" },
"content": { "$push": "$text" }
}
}, {$match:{"count": {"$gt": 1}}
})
上述例程的结果应该创建或替换mongoDB v2.4集合,我如何以有效的方式进行此操作。谢谢。
编辑#1
db.selUserTweets.aggregate({
$group : { "_id" : "$user.id",
"count": { "$sum":1 },
"ids": { "$push": "$_id" },
"content": { "$push": "$text" }
}
}, {$match:{"count": {"$gt": 1}}
}, {$out :{"count": -1}
})
执行时
Error("Printing Stack Trace")@:0
()@src/mongo/shell/utils.js:37
([object Object],[object Object],[object Object])@src/mongo/shell/collection.js:866
@(shell):8
uncaught exception: aggregate failed: {
"errmsg" : "exception: Unrecognized pipeline stage name: '$out'",
"code" : 16436,
"ok" : 0
}
答案 0 :(得分:0)
将MongoDB更新至至少2.6,这样您就可以使用$out运算符来完成您想要的操作。
如果您由于某种原因不想更新到更新版本,则另一个选项是使用MapReduce将您的聚合重写为out-option。