MONGODB Requete avec somme

Bonjour,
Je fais une requête sur ma base Mongo pour retrouver tous les montants concernant un client.
OK, ça fonctionne et je reçois un tableau de montants. (c’est le seul champ récupéré du document.)

Existe-t-il un paramètre possible de la requête pour recevoir la somme de ces montants et donc non plus un tableau mais seulement une valeur.
Je n’ai rien trouvé sur le net concernant cette éventuelle possibilité.

Quelqu’un a-t-il une solution ?
Merci
YC

Using my awesome translation skills (copy paste into google translate) I’ve deciphered the question.

I think you are looking for Mongo Aggregations. However they don’t work with Meteor publications. The alternative is to Create a method on the server to aggregate the list of numbers into a sum and returning the result.

Hope this helps you. The docs for mongo aggregations can be found here:

https://docs.mongodb.com/manual/aggregation/

The guide for meteor methods can be found here:

Oh and please! Please use English. The community is kind and willing to help, but the main language is English. It allows for much more chance that people will help you.

1 Like

Reactive aggregations are possible with the jcbernack:reactive-aggregate package.

3 Likes