0

Let's say I have model A, Model B and Model C

class ModelA(ModelB):
    data = mongoengine.ReferenceField()

class ModelB(Document):
    customer = mongoengine.ReferenceField(ModelC)

class ModelC(Document):
    name = mongoengine.stringField()

I'm able to access this. models.ModelA.objects(customer=customer)

Now I'm trying to filter where customer.name is equal to a name I pass in. Is this possible with mongoengine filters?

I tried using this method but it wont work models.ModelA.objects(customer__name=name)

Shudipta Sharma
  • 5,178
  • 3
  • 19
  • 33
VIC3KING
  • 562
  • 1
  • 5
  • 11

1 Answers1

0

No this is not possible since joins dont exist in mongodb, you need do this in 2 step, first querying the customer based on the name, then query ModelA based on the outcome of the first query.

customer = ModelC.objects.get(name=your_name)
ModelA.objects(customer=customer)
bagerard
  • 5,681
  • 3
  • 24
  • 48