**
* newField: The new field name.
* expression: The new field expression.
*/
{
lines: {$filter: {
input: "$lines",
cond: {$ne: ["$$this", ""]}
}}
}
First filter out the undesirable elements, then on the next stage of the aggregation use $reduce
While it is one more step it is easier to follow. You can have a conditional in $reduce, but you need to have one output for each element in the array. In my example, create a string by concatenation using $reduce. $reduce