mercredi 4 février 2015

MongoDB counts multiple fields


Vote count:

0




Here is the input collection :



{"itemName" : "A1", "voteType" : "up"}
{"itemName" : "A1", "voteType" : "up"}
{"itemName" : "A1", "voteType" : "down"}
{"itemName" : "A2", "voteType" : "up"}
{"itemName" : "A2", "voteType" : "down"}
{"itemName" : "A2", "voteType" : "down"}
{"itemName" : "A2", "voteType" : "down"}
and so on...


Does anyone know how to get the following documents with Aggregation?


Also, how can we use Spring Data to implement this?



{ "id" : "A1", "CountUp" : 2, "CountDown" : 1}
{ "id" : "A2", "CountUp" : 1, "CountDown" : 3}


asked 31 secs ago







MongoDB counts multiple fields

Aucun commentaire:

Enregistrer un commentaire