开发者

Querying ReferenceFields with MongoEngine

I'm playing around w开发者_高级运维ith MongoEngine and i just can't find the way querying ReferenceFields

Class Foo(Document)
    bar = ReferenceField(Bar)
    ...

Class Bar(Document)
    value =IntField()
    ...

bars = Bar.objects.filter(value__lt=1000)

Django:

foos = Foo.objects.filter(bar__in=bars)

MongoEngine : ?

Is there a way to achieve this ?

Thanks in advance,


That is impossible by one query.

try this:

bars = Bar.objects.filter(value__lt = 1000)
foo = Foo.objects.filter(bar__in = bars)

More see. That test scripts.
https://github.com/Ankhbayar/mongoengine/blob/dev/tests/django_tests.py#L73


If you using reference you can't query on referenced object fields. Because referencing done internally in driver and most drivers save referenced document id, collection name and db name (so you can query only on referenced document id).

Want query? Use embedding or make two separate queries.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜