1

I have a nested document that has 54 fields. It looks like this:

{
    "_id" : ObjectId("5af3a985d9ce8a20f726366f"),
    "sampling_time" : ISODate("2018-05-10T09:08:05.458Z"),
    "enose_id" : "node1",
    "value" : [
        {
            "Seconds" : 0,
            "MQ5_ALCOHOL" : 10.51,
            "MQ3_BENZINE" : 0,
            ...
            "MQ138_PROPANE" : 4.47,
            "MQ4_H2" : 72.2
        },
        ...
}

How to do aggregation (SUM, MIN, MAX, MEAN, STD) without specifying all fields in "value" key? How to avoid this way:

db.collection.aggregate( [
{ $unwind: "$value" },
{ $group: {
    _id: '$_id', 
    MQ5_ALCOHOL_SUM: { $sum: '$value.MQ5_ALCOHOL' },
    MQ3_BENZINE_SUM: { $sum: '$value.MQ3_BENZINE' },
    MQ138_PROPANE_SUM: { $sum: '$value.MQ138_PROPANE' },
    MQ4_H2_SUM: { $sum: '$value.MQ4_H2' },
    ...
} } 
] );

0 Answers0