【发布时间】:2018-12-05 15:31:08
【问题描述】:
我尝试用 MongoDB 作为数据库、Apollo GraphQL 和 express 服务器来实现一个房间预订系统。
我必须在我的数据库中收集:一份用于房间,一份用于预订。为了检查可用性,系统会查找数据库中当前的所有预订,并检查在指定时间段内哪些房间是可用的。 如果系统预订了房间,它会在数据库中插入一条新记录。
问题是以下场景,同一房间有两个预订请求:
booking request 1 -> check for available rooms
booking request 2 -> check for available rooms
booking request 1 -> read request success (display available rooms)
booking request 2 -> read request success (display available rooms)
booking request 1 -> write a new record to the db (new booking)
booking request 2 -> write a new record to the db (new booking) but this conflicts with booking 1.
我如何保证一个房间永远不会发生冲突预订?
问题是,我有一个可用性请求和另一个将预订写入数据库的语句。
【问题讨论】:
-
我想我真正的意思是,有没有办法防止幻读以防止重复预订?
标签: mongodb concurrency