MongoDB Aggregation Operations

Source: Internet
Author: User

1, first example analysis of the following MongoDB aggregation operations:

    • This operation indicates that the count quantity under each group is counted according to the whoisserver_id field grouping:
Db.anhui.aggregate ({$group: {_id:'$whoisserver _id', total:{$sum:1}})

The results of the query are as follows:

    • If the total number of queries:
Db.anhui.aggregate ({$group: {_id:null, total:{$sum: 1}})

    • The following query filters and then counts based on criteria
db.anhui.aggregate {$match: {mx:{$exists: 1}}},{$group: {_id: ' $whoisserver _id ', total:{  $sum: 1}})
    • First filter the data equivalent to the where operation in the SQL statement, then group Count, and then match the information with a quantity greater than 30
db.anhui.aggregate {$match: {mx:{$exists: 1}}},{$group: {_id: ' $whoisserver _id ', total:{  $sum: 1}}},{$match: {total:{$gte: 30}})

The following is the data to be queried

Inquire

db.anhui.aggregate {$match: {mx:{$exists: 1}}},{$group: {_id: ' $mx. brand_id ', total:{  $sum: 1}})

MongoDB Aggregation Operations

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.