We know that MongoDB is a kind of relational database, so its query method is very different from the standard Structured Query language SQL. But no matter how complicated a structure it is, when it passes through the developer's hands, it only becomes the structure that the customer wants. Today is about how to MongoDB group group queries under Mongovue.
The Mongovue query format is as follows:
Db.collection.group ({key, reduce, initial, [Keyf,] [Cond,] finalize})
From the above, we can see that to implement the MongoDB group query, key (Group field), cond (group condition), Refuce (group calculation method), initial (initial condition) is MongoDB packet query is not less than the value. Next, we will look at how to implement the MongoDB query function under Mongovue:
(a) Select the table to be grouped, select "Collection--group", and turn on the grouping feature.
(b) Under Key to enter the field to be grouped, conditions under the input packet filter conditions. Open Reducetab page, initial value out input "{" Count ": 0}", below reduce function to enter:
Functionreduce (Doc, out) {
Out.count +=1
}
Select Go, which is the group result that pops up the MongoDB.
(c) At the shell, the MongoDB query is automatically typed.
Db. Equipment.group ({
Key: {
' Equiptype ': true
},
Cond: {
"SiteId": "Beijing"
},
Initial: {
"Count": 0
},
Reduce:function Reduce (Doc, out) {
Out.count +=1
},
Finalize:function Finalize (out) {
return out;
}
});
--This article from: http://www.linuxidc.com/Linux/2014-03/98217.htm