I have the following document structure
_id:2
lines:Array
I want to retrieve the number of lines
items for each document
{
_id: "$_id",
numberLines: {
$size: "$lines"
}
}
It doesn't work !
Then I want get the total lines
items for the entire documents using Aggregation Pipelines
Group only allows accumulators operations, and $size
is not one of those.
However it seems you just need to use the $project
or $addFields
stage as you're not really $group
ing anything.
like so:
{
$project: {
_id: 1,
numberLines: { $size: "$lines" }
}
}