[Mongodb]count,gourp,distinct

Source: Internet
Author: User

Summary

The previous article introduced CRUD operations, which will basically do a lot of work. However, if you encounter the operation of statistical classes, then you need to learn the contents of this article.

Related articles

Getting started with [MongoDB]

[MongoDB] additions and deletions change

Count,gourp,distinct,mapreduce

Count

Functions like the Count function in SQL, which is used to count.

As shown, it lists the methods with no parameters, with parameters, and the count after find.

Distinct

Go to weight, receive field parameters, semantics: Press a field to go heavy. For example, we press name to go heavy.

Group

As the name implies, the meaning of grouping is the same as group by in SQL. But the group is more complex in MongoDB.

Parameters:

Key: Group by Key.

Initial: "Initialization function" shared by each group. You can initialize a number of variables here for use by each group.

$reduce: The function has two parameters, the first parameter is the current document object, and the second parameter is the cumulative object of the last operation. How many $reduce will be called in the collection number of document.

Condition: Filter conditions.

Finalize: This function will be called after each set of document execution completes, in this function, you can do some follow-up work, such as counting operations, the number of statistical results.

Example: Group by age to find the person's name for each of the ages. One of the following:

Figure A

Count, after grouping, the number of qualified user.

Summarize

This article describes common collection aggregation operations. Among them, group operation is a bit more troublesome. Understanding the role of group parameters, usually these commands can save a template. Use the time to dip in the past, on this basis to make changes more convenient point. Because it's too long.

Reference

Http://www.cnblogs.com/huangxincheng/archive/2012/02/21/2361205.html

[Mongodb]count,gourp,distinct

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.