【发布时间】:2020-07-01 00:45:22
【问题描述】:
我已经坚持了几个小时了。我需要编写一个查询来返回 (Field A - Field B) > N
// sample data
{ _id: '...', estimated_hours: 0, actual_hours: 0 },
{ _id: '...', estimated_hours: 10, actual_hours: 9 },
{ _id: '...', estimated_hours: 20, actual_hours: 30 }
从this stack question 借用答案我写了下面的内容,在我看来这应该可行,但是我一直收到与查询不匹配的记录...
## Attempt 1
n = 0
records = API::Record.where('$where': "(this.estimated_hours - this.actual_hours) > #{n}")
## should return the following, but im getting additional records
#=> [{ _id: '...', estimated_hours: 10, actual_hours: 9 }]
我知道我可以使用$project 完成此操作,但是我必须明确告诉$project 我想要返回哪些字段。我需要返回所有字段,我们使用处理分页的第三方库
【问题讨论】:
-
我觉得不需要
$where:,试试.where("(this.estimated_hours - this.actual_hours) > #{n}")