Database
Gather/Aggregate results with MongoDBGrouper/agréger les résultats avec MongoDB
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:
1 2 3 4 5 6 7 8 9 10 |
db.collection.group( { key: { document: 1}, cond: { }, reduce: function( curr, result ) { result.total += 1; }, initial: { total : 0 } } ) |
You will get something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[ { "document" : "my_first_document", "total" : 44124 }, { "document" : "my_second_example", "total" : 3503 }, { "document" : "still_another_one", "total" : 3928 } ] |
Here you are!Besoin de grouper ou agréger certains résultats avec MongoDB ? Facile !
Vous pouvez utiliser la commande group sur n’importe quelle collection pour obtenir un affichage de vos résultats agrégés plutôt plaisant :
1 2 3 4 5 6 7 8 9 10 |
db.collection.group( { key: { document: 1}, cond: { }, reduce: function( curr, result ) { result.total += 1; }, initial: { total : 0 } } ) |
Vous obtiendrez quelque chose comme :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[ { "document" : "my_first_document", "total" : 44124 }, { "document" : "my_second_example", "total" : 3503 }, { "document" : "still_another_one", "total" : 3928 } ] |
Et voilà !