Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying ReferenceFields with MongoEngine

I'm playing around with 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,

like image 275
Philippe Clément Avatar asked Jul 04 '11 10:07

Philippe Clément


1 Answers

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

like image 110
Ankhaa Avatar answered Nov 15 '22 20:11

Ankhaa