content_image/663773.jpg
Map-reduce uses custom JavaScript functions to perform the map and reduce operations, as well as the optional finalize operation. While the custom JavaScript provide great flexibility compared to the aggregation pipeline, in general, map- reduce is less efficient and more complex than the aggregation pipeline. 

Note: Starting in MongoDB 2.4, certain mongo shell functions and properties are inaccessible in map-reduce op- erations. MongoDB 2.4 also provides support for multiple JavaScript operations to run at the same time. Before MongoDB 2.4, JavaScript code executed in a single thread, raising concurrency issues for map-reduce. 

<img src='content_image/663773.jpg'>

## Single Purpose Aggregation Operations 

For a number of common single purpose aggregation operations (page 444), MongoDB provides special purpose database commands. These common aggregation operations are: returning a count of matching documents, returning the distinct values for a field, and grouping data based on the values of a field. All of these operations aggregate documents from a single collection. While these operations provide simple access to common aggregation processes, they lack the flexibility and capabilities of the aggregation pipeline and map-reduce. 

