How to avoid two concurrent API requests breaking the logic behind document validation?
问题 I have an API that in order to insert a new item it needs to be validated. The validation basically is a type validator( string , number , Date , e.t.c) and queries the database that checks if the "user" has an "item" in the same date, which if it does the validation is unsuccessful. Pseudocode goes like this: const Item = require("./models/item"); function post(newDoc){ let errors = await checkForDocErrors(newDoc) if (errors) { throw errors; } let itemCreated = await Item.create(newDoc);