We know that MongoDB is a non-relational database, so its query method is very different from the standard Structured Query language SQL. But no matter how complex a structure it is, when it passes through the developer's hands, it can only become the structure that the customer wants. Today is to tell the Mongovue how to MongoDB group Group query.
The query format for Mongovue is as follows:
Db.collection.group ({key, reduce, initial, [Keyf,] [Cond,] finalize})
From the above, we can see that in order to implement the group query of MongoDB, key (Group field), cond (grouping condition), Refuce (grouping method), initial (initial condition) are the values that the MongoDB packet query is not very small. Next, let's look at how to implement the MongoDB packet query function under Mongovue:
(a) Select the table you want to group, select "Collection--group", and turn on the grouping function.
(b) Enter the field to be grouped under key and enter the grouping filter under conditions. Open Reducetab page, in initial value out input "{" Count ": 0}", below the reduce function input:
Functionreduce (Doc, out) {
Out.count +=1
}
Select Go, which pops up the group results for MongoDB.
(c) At the shell, the query statement of MongoDB 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 transferred from: http://www.linuxidc.com/Linux/2014-03/98217.htm