I have following nested object to update after some conditions.based on the condition finally iwant to update promotional or transactional value
{
"_id" : "XX1",
"credit" : {
"sms" : {
"credit" : {
"promotional" : 0,
"transactional" : 1231
}
},
"viber" : {
"credit" : {
"promotional" : 10,
"transactional" : 50
}
},
"whatsapp" : {
"credit" : {
"promotional" : 30,
"transactional" : 40
},
}
},
}
conditions will based on the passing variable values
accountId = "XX1",
channel = "sms",
messageType = "promotional",
credit = 150
these are the conditions should check befor update
_idshould match withaccountId- if
channel='sms',it should selectcredit.sms - if
messageType = "promotional"then check promotional value is greater than tocreditor not - if it is greater than to
creditvalue (credit.sms.credt.promotional) should update with :(credit.sms.credt.promotional)-credit