Mongo字段A大于字段B [英] Mongo field A greater than field B
本文介绍了Mongo字段A大于字段B的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在Mongo中尝试一个简单的查询,在MySQL中看起来像这样.
i'm trying a simple query in Mongo which in MySQL would look like this.
select * from emails where bounceCount > sentCount;
到目前为止,我有.
db.email.find({ bounceCount : { $gt : sentCount } } );
但是我得到这个错误
JS Error: ReferenceError: sentCount is not defined (shell):0
如何在该shell中引用sendCount?
How do I reference the sentCount in that shell?
推荐答案
每个人似乎都在不真正知道$where
的情况下提到了$where
:
Everyone seems to mention $where
without really knowing that it is:
- 慢
- 不安全(逃避)
- JavaScript,而不是MongoDB内部
- 并且,在2.4之前的版本中,单线程和全局锁定
另一种在大约99%的情况下会更好的方法是使用聚合框架:
Another method which would be a lot better for about 99% of cases is to use the aggregation framework:
db.col.aggregate([
{$project: {ab: {$cmp: ['$bounceCount','$sentCount']}}},
{$match: {ab:{$gt:0}}}
])
这篇关于Mongo字段A大于字段B的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文