完全不明白
db.users.aggregate(
[
{
$group : {
_id: { $sum: 1 }
}
}
]
)
Error: Printing Stack Trace
at printStackTrace (src/mongo/shell/utils.js:37:15)
at DBCollection.aggregate (src/mongo/shell/collection.js:897:9)
at (shell):1:10
Fri Sep 19 18:51:23.623 aggregate failed: {
"errmsg" : "exception: invalid operator '$sum'",
"code" : 15999,
"ok" : 0
迷茫2017-04-24 09:13:18
_id
是用来 GROUP(分组) 的,如果你要用 $sum, 需要换一个字段名。
http://docs.mongodb.org/manual/reference/operator/aggregation/sum/#grp._S_sum