Node.js mongodb查找低于另一个字段加上参数值的where字段

Node.js mongodb查找低于另一个字段加上参数值的where字段,node.js,mongodb,Node.js,Mongodb,我在mongodb中收集了以下产品,我们称之为“产品”: 我希望有一个find()查询,返回此集合中“warehouseStock”小于('reservedStock'+阈值)的文档,其中阈值是传递到find()查询中的参数 我正在尝试在节点中执行以下find()查询: var threshold = 10; mongo.getDb().collection('products').find({warehouseStock: {$lt:(threshold+'$reservedStock')}}

我在mongodb中收集了以下产品,我们称之为“产品”:

我希望有一个find()查询,返回此集合中“warehouseStock”小于('reservedStock'+阈值)的文档,其中阈值是传递到find()查询中的参数

我正在尝试在节点中执行以下find()查询:

var threshold = 10;
mongo.getDb().collection('products').find({warehouseStock: {$lt:(threshold+'$reservedStock')}})
但这似乎不起作用。我知道我可以做到以下几点:

mongo.getDb().collection('products').find({warehouseStock: {$lt:threshold}})
但我怎么能问在哪里

warehouseStock < (reservedStock + threshold)
仓库库存<(储备库存+阈值)
所以,如果threshold是=10,那么我只会得到上面集合示例中两个项目中的第一个

谢谢大家!

您可以使用:

var阈值=10;
mongo.getDb().collection('products')。查找({
“$where”:“this.warehouseStock<(this.reservedStock+“+threshold+”)
}).toArray(功能(错误、项目){
控制台日志(项目);
});

非常感谢您。我也尝试了$where,但我没有用引号括起来。再次感谢大家!
warehouseStock < (reservedStock + threshold)
var threshold = 10;
mongo.getDb().collection('products').find({
    "$where": "this.warehouseStock < (this.reservedStock + " + threshold + ")"
}).toArray(function(err, items) {
    console.log(items);
});