Unexpected behavior on multiple parallel update requests #1409
Replies: 1 comment 3 replies
-
Hey @383bd03d — I see what you're going for here but I also understand why this does not work. Right now the full existing document is merged into the incoming data within each update operation. Meaning——your parallel requests are overlapping one another and could be writing as another saves. However, you could access the raw Mongoose model for your collection by Outside of that, this would need to be a new feature that Payload provides. Could be possible at some point so I'm going to convert this to a discussion and tag it as a feature request! How's that? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I tested multiple async request to api endpoint for update existing document with different fields. (One request updates one field)
If entry created with empty fields, in mongodb document this fields doesnt exists, that allows successfully update all empty fields with multiple parallel api requests, but if field have value and after its deletion fields keep in mongodb with empty value { "field": "" }
This kind of fields dont updates with multiple parallel request, only one random field could updated
Example request:
const f = (body) => fetch("http://localhost:4000/api/test/6372638638bead8eb92b0018", {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body)
});
Promise.all([
f({ qwe: "rterte" }),
f({ wer: "ert" }),
f({ ert: "fdgd" }),
f({ rty: "ok" }),
f({ asd: "fhfh" }),
f({ sdf: "rt" }),
f({ zxc: "dfg" }),
f({ xyz: "sdf" }),
f({ vbn: "odfdfgk" }),
f({ foo: "dfgdgd" }),
]).then((r) => r.map(async(i) => console.log(await i.json())))
Beta Was this translation helpful? Give feedback.
All reactions