我的收藏结构*"countcollection"*如下所示
{
"limitcount": 10000,
"currentcount": 100
}
Run Code Online (Sandbox Code Playgroud)
我想纠正能够比较currentcount<($lt)limitcount
或者的mongoquery currentcount>($gt)limitcount
.
首先,我写了如下的mongo查询
db.countcollection.find({"currentcount":{$lt:{"limitcount"}}});
db.countcollection.find({"currentcount":{$gt:{"limitcount"}}});
Run Code Online (Sandbox Code Playgroud)
但它没能执行.
请为这个mongoquery提供你的意见.
提前致谢 .
javaamtho.
正如Bugai13所说,你无法对查询中的2个字段进行比较.
$ where的问题在于性能 - 因为这是一个将为每个文档执行的javascript函数,因此它必须扫描每个文档.
因此,您可以存储另一个字段(您可以将其编入索引)与这些现有字段一起存储
例如
{
"limitcount": 10000,
"currentcount": 100,
"remainingcount" : 9900
}
Run Code Online (Sandbox Code Playgroud)
这样你就可以在新字段上查询:
db.countcollection.find({"remainingcount" : {$gt : 0}})
db.countcollection.find({"remainingcount" : {$lt : 0}})
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2720 次 |
最近记录: |