I'm working on a delivery service where I'm processing 8 orders at the same time concurrently, for each of these orders, I must get a unique consignment number that is saved on the database. But since the operations are concurrent, they are all picking up the same object/consignment number.
const query = new Parse.Query("Consign")
query.doesNotExist("order")
query.equalTo("staging", staging)
query.exists("number")
query.limit(1)
await query.find().then(function (result) {
if (result.length > 0) {
order.set("consign_no", result[0].get("number"))
result[0].set("order", order)
} else {
//failed
}
}).catch((err)=>{
console.log(err);
})
How do I make this query in such a way that it picks up unique objects even when ran concurrently?