We have a calendar API for booking a slot during a day
SlotShcema
startDateTime:Date // showing the day and the starting hour
duration:number // showing the slot duration
we can calculate the slot end
endDateTime = startDateTime + duration
We want add a validation, so no two slot intersect, and only one user can book it .
I found costume Async Custom Validators, but we cannot find any doc for our scenario .
The issue is to find way to solve the race condition where two concurrent saves might save conflicting bookings "transaction" . i did my own validate function before start create the slot, but if there is a race condition it may save two slots at same time which is wrong . Is there any way to solve the race condition ?
Issue on GitHub https://github.com/Automattic/mongoose/issues/5876