Hello I've been a little stumped on this for a few days. Due to mongo being pretty outdated where I work I can't use a switch statement since it's not supported in our version. I am trying to accomplish my task with nested if/else. The first condition gets evaluated and the second myField2 is getting set but none of the inner if/else conditions work. I can't tell what I'm doing wrong with this one.
db.getCollection("MyCollection").updateMany({
//SOME CONDITIONS CHECKED HERE
},
[{
"$set":{
"myTs":{
"$cond":{
"if":{
"$and": [
{"myField1" : "value1"},
{"myField2": "value2"},
]
},
"then":"$ThisTs",
"else": {
"$cond":{
"if":{
"myField2": "value3"
},
"then":"$lastUpdatedTs",
"else":{
"$cond":{
"if":{
"$and": [
{"myField1" : "value4"},
{"$ne": ["$myField3.aTs", null]},
{"$ne": ["$myField3.aTs", "0"]},
{"$eq": ["$myField3.aBool", false]},
]
},
"then":"$myField3.aTs2",
"else":{
"$cond":{
"if":{
"$and": [
{"myField1" : "value2"},
{"myField2" : "value1"},
{"$or": [
{"$eq": ["$myField3.aTs", null]},
{"$eq": ["$myField3.aTs", "0"]},
{"$eq": ["$myField3.aBool", false]},
]
},
]
},
"then":"$myField3.aTs",
"else": "$lastTs",
}
}
}
}
}
}
}
},
"myField2":{
"$cond":{
"if":{
"$and": [
{"myField1" : "value2"},
{"$ne": ["$myField3.aTs", null]},
{"$ne": ["$myField3.aTs", "0"]},
{"$eq": ["$myField3.aBool", false]},
]
},
"then":"FINISHED",
"else": "$myField2"
}
}
}
}], {multi: true}
)
I'm getting a little turned around with this one. Any pointers in the right direction? I haven't been able to find too much information on nested if/else.