Group Group query of MongoDB implemented under Mongovue

Source: Internet
Author: User
Tags mongodb

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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.