Hi everyone! I’m doing this project using Express, mongodb(MongoDB Atlas) & mongoose and this is what my app will do when a request arrives: it will query if this url existed. If not then insert new document, else get the existed one and return to user.
Here’s a user story: When 2 requests (A & B) with the same url arrives at the same time and the url isn’t in database yet, I think this is what will happen because find and add is asynchronous:
my app finds the url for A (not existed)
-> my app finds the url for B (not existed)
-> add the url to database (request A)
-> add the url to database (request B) => but the url is already existed so this is wrong.
I wonder if i understand it right? If yes, how can i solve this? If not then how will it works in this case?