Implement Group query for MongoDB under the same vue

Source: Internet
Author: User
Tags mongodb query
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

,

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.