I am trying to add the values of each document and in each collection. I explain myself better, I have 5 collections in MongoDB and in each collection I have more than 280,000 documents. Something like that.
1st Collection.
"_id" : ObjectId("5ad99a8a02e5f720785a9b57"),
"fecha" : ISODate("2010-01-01T00:00:00.000Z"),
"magnitud1" : {
"valor" : 46
},
"magnitud2" : {
"valor" : 168
}
2nd Collection.
"_id" : ObjectId("5ad99e4602e5f722f8e665e8"),
"fecha" : ISODate("2010-01-01T00:00:00.000Z"),
"magnitud1" : {
"valor" : 172
},
"magnitud2" : {
"valor" : 105
},
3rd Collection.
"_id" : ObjectId("5ad9a1b202e5f71c7c1d4374"),
"fecha" : ISODate("2010-01-01T00:00:00.000Z"),
"magnitud1" : {
"valor" : 153
},
"magnitud2" : {
"valor" : 38
},
and thus up to 5 collections ... where each collection has more than 280,000 documents, as I have already commented. I've tried this.
db.medidor01.aggregate([
{$match: {fecha: { $gte: ISODate("2010-01-01T00:00:00.000Z"), $lte: ISODate("2011-01-01T00:00:00.000Z") }} },
{$unwind: "$magnitud1"},
{$group: {
_id: null,
"total": {$sum: "$magnitud1.valor" }
}}
])
But this what it does is add the values that are in the collection meter01 .
Exit:
{
"_id" : null,
"total" : 3495890
}
What I want to do is the same but with all the collections in my database, which has the same structure.
I've looked at SO.com and I've seen that they say it's not possible perform this operation, although I'm not sure it's the same question as mine.
Therefore, my initial question is; Is it possible to perform this operation, add the values of all the collections in my database?