【发布时间】:2017-08-13 06:57:49
【问题描述】:
我正在开发任务查询。当请求任务时,我将返回最旧的任务,代码如下:
Task.find({})
// Filter for those that are not started yet
.where('startDate').equals(null)
// Sort ascending to get the oldest
.sort({ reqDate: 'asc' }).findOne(function (err, task) { ... }
在最后的括号内,我将 startDate 设置为当前时间。 这些请求是通过调用运行 express 并使用 Mongoose 与 MongoDB 通信的单个 NodeJS (Express) API 来完成的。
这适用于只有一个人请求任务,但我现在正在考虑一个巨大的规模。如果有多个人在同一时刻发出请求,所有人都在几毫秒的同一时间跨度内收到相同的任务怎么办?
有没有办法确保文件的startDate在被猫鼬找到的那一刻设置?
【问题讨论】: