MongoDB Documentation, Release 3.0.4 that merge replace, merge, or reduce new results with previous results. See mapReduce and Perform Incremental Map-Reduce (page 463) for details and examples. When returning the results of a map reduce operation inline , the result documents must be within the BSON Document Size limit, which is currently 16 megabytes. For additional information on limits and restrictions on map-reduce operations, see the http://docs.mongodb.org/manual/reference/command/mapReduce reference page. MongoDB supports map-reduce operations on sharded collections (page 661). Map-reduce operations can also output the results to a sharded collection. See Map-Reduce and Sharded Collections (page 451). Aggregation refers to a broad class of data manipulation operations that compute a result based on an input and a spe- cific procedure. MongoDB provides a number of aggregation operations that perform specific aggregation operations on a set of data. Although limited in scope, particularly compared to the aggregation pipeline (page 439) and map-reduce (page 442), these operations provide straightforward semantics for common data processing options. MongoDB can return a count of the number of documents that match a query. The count command as well as the count() and cursor.count() methods provide access to counts in the mongo shell. Given a collection named records with only the following documents: The following operation would count all documents in the collection and return the number 4 : db.records.count() db.records.count( { a: 1 } ) The following operation will count only the documents where the value of the field a is 1 and return 3 : The distinct operation takes a number of documents that match a query and returns all of the unique values for a field in the matching documents. The distinct command and db.collection.distinct() method provide this operation in the mongo shell. Consider the following examples of a distinct operation: Given a collection named records with only the following documents: { a: 1, b: 0 } { a: 1, b: 1 } { a: 1, b: 1 } { a: 1, b: 4 } { a: 1, b: 0 } { a: 1, b: 1 } { a: 1, b: 4 } { a: 2, b: 2 } Example Distinct Example Count 7.2.3 Single Purpose Aggregation Operations Chapter 7. Aggregation 444