2

例如..

class Example(Document):
    up = IntField()
    down = IntField()

并且.. 我想检索 up 字段大于或等于 down 的文档。但是..这是问题。

我的错误查询代码是..

Example.objects(up__gte=down)

如何使用驻留在 mongodb 而不是 python 代码中的字段作为查询集值?

4

2 回答 2

4

简单的回答:不可能。SQL 中的 WHERE A = B 之类的东西在 MongoDB 中无法以有效的方式实现(除了应该避免使用 $where 子句)。

于 2012-03-12T05:28:15.453 回答
0

这可能是你想要的::

db.myCollection.find( { $where: "this.credits == this.debits" } );

看看:http ://docs.mongodb.org/manual/reference/operator/query/where/

但我不知道如何在 mongoengine 中使用它。

于 2015-01-30T09:15:28.080 回答