> ## Content Index
> Fetch the complete content index at: https://www.bagz.fr/llms.txt
> Use this file to discover other available public pages before exploring further.

# Gather/Aggregate results with MongoDB
- URL: https://www.bagz.fr/gatheraggregate-results-with-mongodb/
- Published: 2015-11-26T14:13:50.000Z
- Updated: 2015-11-26T14:13:50.000Z
- Author: bgazui
- Tags: Database, #Migrated-1790668826633, #wp, #wp-post, #Import 2026-09-29 08:00

Need to gather or aggregate some results with MongoDB? Easy!

You can use the *group* command over any collection to get a nice display of your results aggregated:

db.collection.group(  
 {  
 key: { document: 1},  
 cond: { },  
 reduce: function( curr, result ) {  
 result.total += 1;  
 },  
 initial: { total : 0 }  
 }  
)  

You will get something like:

\[  
 {  
 "document" : "my\_first\_document",  
 "total" : 44124  
 },  
 {  
 "document" : "my\_second\_example",  
 "total" : 3503  
 },  
 {  
 "document" : "still\_another\_one",  
 "total" : 3928  
 }  
\]  

Here you are!