How can we setup conditionally unset value
if watched.3 exists then remover 3 and fans = -2 else add watched.3 and fans +1
db.collection.update({
_id: ObjectId(“60e80c96b9c55e7a01898f5c”)
},
[
{
“$set”: {
“fans”: {
“$add”: [
“$fans”,
{
“$cond”: {
“if”: {
“$ne”: [
“$watched.3”,
undefined
]
},
“then”: 1,
“else”: -2
}
}
]
}
}
},
{
“$unset”: “watched.3”
}
])