For example,
{user: "user1", filed1: "filed1"}
{user: "user1", filed1: "filed1"}
{user: "user1", filed1: "filed1"}
{user: "user2 filed2:" filed2 "}
{user: "user2 filed2:" filed2 "}
I query a can get user1 has 3, user2 have 2
For help
CodePudding user response:
http://docs.mongodb.org/manual/reference/method/db.collection.group/Directing a group, but he is aggregation function need to implement a js
CodePudding user response:
Can directly use aggregate to implementIf a table is called a
Db. A.a ggregate (
{$group: {_id: "$user," num: {$sum: 1}}}
)
CodePudding user response:
Db. Collection. Aggregate ([{$group: {user: "$user," the count: {$sum: 1}}}]Where user : "$user" best use _id
CodePudding user response:
Graphs can be used for processing the db. Collection. Graphs (function () {$emit {this user, 1}), function (key, values) {return Array. The sum (values)}, {out: 'new_temp}). The find ()