could you please suggest how to get an average size of a document in a group via aggregation? I have the following query:
db.Collection.aggregate(
[
{
$match: {
date: {
$gte: ISODate("2020-04-29 14:18:22.560Z"),
$lt: ISODate("2021-04-30 14:18:22.560Z")
}
}
},
{
$group: { _id: '$objectType', count:{ $sum:1 }, avgSize: { $avg: ??? } }
}
]
)
Collection sample doc:
{
"_id" : UUID("..."),
"date" : ISODate("2020-04-29T14:18:22.560Z"),
"objectType" : << string >>,
"previousState" : << pretty long json >>,
"currentState" : << pretty long json >>
}
I suspect it should be something with Object.bsonsize, but can't get what exactly.