I am trying to execute this unwind pipeline stage:
{
path: {$cond: {
if: {$size: {'$actionBy': {$gte: 2}}},
then: '$actionBy',
else: '$meta'
}},
preserveNullAndEmptyArrays: true
}
Error displayed is: 'expected a string as the path for $unwind stage, got object' which of course is self explanatory, but is there not a way to do this?!
CodePudding user response:
You can do it in two steps. Something like:
{$set: {data:
{$cond: {
if: {$size: {'$actionBy': {$gte: 2}}},
then: '$actionBy',
else: '$meta'
}}
}},
{$unwind: {path: '$data', preserveNullAndEmptyArrays: true}}