MongoDB Aggregation Pipeline (aggregate)

Source: Internet
Author: User

1. Aggregation function
    • Total number of queries. COUNT ()
>Db.userinfo.count ()3> Db.userinfo.Find(){ "_id":1,"name":"Uncle Guo","Sex":"male"," Age":" the" }{ "_id":2,"name":"Miss Guo","Sex":"male"," Age":"Unknown" }{ "_id":3,"name":"Master Guo","Sex":"male"," Age":" -"}
2. Aggregate () method

Let's insert some test data first.

{     "_id": ObjectId ("5abc960c684781cda6d38027"),     "Name": "Uncle Guo",     "Sex": "Male",     "Age": 80.0,     "Skil" : [        "PHP",         "Js",         "MYSQL",         "Html",         "Css"    ]}{     "_id": ObjectId ("5abc960c684781cda6d38028"),     "Name": "Uncle Guo",     "Sex": "Male",     "Age": 60.0,     "Skil" : [        "PHP",         "MYSQL"    ]}{     "_id": ObjectId ("5abc960c684781cda6d38029"),     "Sex": "Female"}{     "_id": ObjectId ("5abc960c684781cda6d3802a"),     "Name": "Master Guo",     "Sex": "Male",     "Age": 18.0,     "Skil" : [        "Css",         "Java",         "Html"    ]}
    • Sum

Check the sum of all ages

db.userinfo.aggregate ([    {$group: {        null,        ' $age '}}    }])

Results

{     null,     "age_sum": 158.0}
    • Average
    • Minimum value
    • Maximum Value
    • Get the first document
    • Get the last document

MongoDB Aggregation Pipeline (aggregate)

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.