db.collectionName.aggregate([
{
$group:
{ _id: null,
totalSize:
{ $sum:
{ $add:
[{ $size: "$test"},-1]
}
}
}
}
])
Проверено по приведенным ниже данным
/* 1 */
{
"_id" : ObjectId("5e31333fab4013230264d786"),
"condition" : "testCase1",
"test" : [
ISODate("2020-01-29T07:26:42.491Z"),
ISODate("2020-01-29T07:27:42.491Z")
]
}
/* 2 */
{
"_id" : ObjectId("5e313346ab4013230264d787"),
"condition" : "testCase2",
"test" : [
ISODate("2020-01-29T07:25:42.491Z"),
ISODate("2020-01-29T07:24:42.491Z"),
ISODate("2020-01-29T07:23:42.491Z")
]
}
Вывод:
{
"_id" : null,
"totalSize" : 3.0
}