MongoDB Documentation, Release 3.0.4 Additional Resources 7.4.4 Aggregation Commands Aggregation Commands Aggregation Methods 7.4.5 Variables in Aggregation Expressions User Variables System Variables • MongoDB and MySQL Compared 22 • Quick Reference Cards 23 • MongoDB Database Modernization Consulting Package 24 Aggregation expressions (page 470) can use both user-defined and system variables. Variables can hold any BSON type data (page 178). To access the value of the variable, use a string with the variable name prefixed with double dollar signs ( $$ ). If the variable references an object, to access a specific field in the object, use the dot notation; i.e. "$$<variable>.<field>" . User variable names can contain the ascii characters [_a-zA-Z0-9] and any non-ascii character. User variable names must begin with a lowercase ascii letter [a-z] or a non-ascii character. MongoDB offers the following system variables: $^{22}$http://www.mongodb.com/mongodb-and-mysql-compared?jmp=docs $^{23}$https://www.mongodb.com/lp/misc/quick-reference-cards?jmp=docs $^{24}$https://www.mongodb.com/products/consulting?jmp=docs#database_modernization Chapter 7. Aggregation 478 Name Description db.collection.aggregate() Provides access to the aggregation pipeline (page 440). db.collection.group() Groups documents in a collection by the specified key and performs simple aggregation. db.collection.mapReduce() Performs map-reduce (page 442) aggregation for large data sets. Name Description aggregate Performs aggregation tasks (page 439) such as group using the aggregation framework. count Counts the number of documents in a collection. distinct Displays the distinct values found for a specified key in a collection. group Groups documents in a collection by the specified key and performs simple aggregation. mapReduce Performs map-reduce (page 442) aggregation for large data sets.