Hi,
I saw that mongo 4.4 added that ability to get bsonSize inside aggregation but I’m working with mongo 4.2
I wanted to know if there is any way to get the size of a field (or the full document) with aggregation.
This is the query I want to execute
db.temp_coll.aggregate([
{
"$match": {}
},
{
"$addFields": { "size": {$bsonSize: "$$ROOT"}}
},
{
"$group": {
"_id": {
"groupField": "$groupField",
},
"count": {"$sum": 1},
"totalSizeBytes": {"$sum": "$size"},
"maxId": {"$max": "$_id"},
"minId": {"$min": "$_id"},
}
}
])
I know there is Object.bsonsize but not sure how can I access (if I can) to a value of a field in the current document (when I do it before the grouping.