Consultation Mongo ForEach

0

I was trying to get a query that for each zip code gives me back the sum of all the accommodations in that area and I'm stuck at this point.

The result of above are the different postal codes and the one below the sum of the prices of the accommodations of the "48006". What I do not get is that it shows me the sum for each existing postal code. Any idea?

I've tried this below, but it only returns the last value

var distintos=db.alojamientos_wimdu.distinct( "location.cp" )//Selecciona los CPs distintos

for(i=0;i<distintos.length;i++){

    db.alojamientos_wimdu.aggregate([
        {$match: { "location.cp":distintos[i]}},
        {$group:{_id:distintos[i],total:{$sum:"$prices.2018.02.16.20180206082009_223.price"}, count: { $sum: 1 }

}}])//Suma todos los apartamentos por CP
}
    
asked by Jonan87 19.02.2018 в 08:47
source

0 answers