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 complicated it is, when it passes through the developer's hands,
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 complicated it is, when it passes through the developer's hands,
(1) Select the table to be grouped and select "Collection -- Group" to enable the grouping function.
(2) enter the fields to be grouped under the Key, and enter the grouping filtering Conditions under Conditions. Open the ReduceTab page and enter "{" count ": 0}" in the Initial Value field. Enter the following in the Reduce function:
FunctionReduce (doc, out ){
Out. count + = 1
}
Select GO to display the MongoDB group results.
(3) In Shell, the MongoDB query statement is automatically output.
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 is from the "Sky with dust" blog. Be sure to keep this source
,