In MongoDB, I am having a collection named foo:
{ "_id" : ObjectId("5837199bcabfd020514c0bae"), "x" : 1 }
{ "_id" : ObjectId("583719a1cabfd020514c0baf"), "x" : 3 }
{ "_id" : ObjectId("583719a6cabfd020514c0bb0") }
I implemented the following query:
db.foo.aggregate({$group:{_id:1, avg:{$avg:"$x"}, sum:{$sum:1}}})
The output is:
{ "_id" : 1, "avg" : 2, "sum" : 3 }
I want to know the meaning of {$sum:1} in the query.