Currently, I am developing a delivery service that processes 8 orders simultaneously, each requiring a unique consignment number to be stored in the database. However, due to the concurrent nature of the operations, the system is assigning the same object/consignment number to all orders.
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);
})
Is there a way to modify this query to ensure unique objects are picked up even when executed concurrently?