The problem is not exactly the same because my need to set several fields conditionally was one level deep, I found that $mergeObjects would do the trick:
{
$set: {
myProp: {
$mergeObjects:[
"$myProp",
$cond: [
$ne: ["$isLastReceiveTime", null],
{
complete: true,
completedTime: "$$NOW"
},
{
complete: "$$REMOVE",
completedTime: "$$REMOVE"
}
]
]
}
}
}
For your use case probably a combination of $replaceRoot and $$ROOT would achieve the same effect.