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