DOCUMENT#1
{
“id”: 1,
“sessionId” : “XFFDFDFD2232”,
“products”: [
{
“id”: 1,
“basketId” :2323232,
“code” : “A23232”,
“qty” : 5,
“mode” :1
},
{
"id": 1,
"basketId" :535353,
"code" : "23232FFD",
"qty" : 15,
"mode" :2
},
{
"id": 1,
"basketId" :75565,
"code" : "43432FDFD",
"qty" : 25,
"mode" :1
},
{
"id": 1,
"basketId" :87878,
"code" : "DSKD343",
"qty" : 1,
"mode" :1
},
{
"id": 1,
"basketId" :2121,
"code" : "REIURE",
"qty" : 200,
"mode" :1
},
{
"id": 1,
"basketId" :54354,
"code" : "FHJDF",
"qty" : 5,
"mode" :1
}
]
}
We have document in above format. Initially when we designed we expected (delete of nested documents in single calls with combination of one id and basketid
So it was working fine. But now there is a possiblity of parallel calls upto 5 to our API.
Say eg. Call#1 (id & basketId ) 1, 2323232
Call#2 (id & basketId ) 1, 535353
Call#3 (id & basketId ) 1, 2121
Sometimes all three record gets deleted and sometimes only 1 get deleted. Later we realized parallel calls is causing this issue as these three calls
updating the same document.
We are using Update statement to delete the nested document that matches the condtion using ARRAY_REMOVE with filters on basketId and parent document id
how to handle this scenario so that all the three records should get deleted. I looked into CAS and getAndLock but not able get it correctly.
Please advise. Thanks