【发布时间】:2021-08-05 15:59:02
【问题描述】:
我有一个集合,其中包含要使用另一个系统处理的作业的多个文档。我从这个表中查找 5 个对象,如下所示:
Work.find({status: 'new'})
.sort({priority: 'desc'})
.limit(5)
.exec(function (err, work){})
这些文档中的另一个字段决定了只能同时运行一个具有给定唯一值的作业。
例如这 3 个工作:
{uniqueVal: 1, priority: 1, type: "scrape", status:"new"}
{uniqueVal: 1, priority: 1, type: "scrape", status:"new"}
{uniqueVal: 2, priority: 1, type: "scrape", status:"new"}
有 2 条 uniqueVal 为 1 的记录。我能做些什么来只提取一条值为 1 的记录吗?
注意:这些值不是示例中的预先确定的值,它们是其他文档的 ObjectId。
我查看了 Distinct(),但它似乎只返回实际的唯一值,而不是文档本身。
【问题讨论】:
标签: node.js mongodb mongoose nosql