I've a node application deployed on Azure App Service and we've scaled it to 5 instances.
Now in our application we have exposed few API's which adds data into our mongo DB collection called detail.
Now these details needs to be pushed to another application with a unique reference id. So While putting the data in the detail collection, apart from the mongo DB Object Id, we are generating a reference_id in a sequential manner.
reference_id = order_category_id + order_sub_category_id + sequence_number + 1
But when multiple requests are coming at the same time for same category and adding the data into the detail collection its generating the same reference_id.
How could I prevent this?
I've tried using the unique Schema property of mongoose, but that is also not working. I want to generate the unique reference Ids in my current system.