1

I am using django-mongodb-engine

Here, I used MongoDBManager to use a raw query.

class NameInfo(models.Model)
   first_name = models.CharField(max_length=50)


class Abc(models.Model):
    name = EmbeddedModelField('NameInfo')
    objects = MongoDBManager()

Abc.objects.raw_query({'name.firstname.contains':'j'})

The last line is not working as expected. So, how can I use the contains lookup type on embedded fields?

If there is another workaround not using MongoDBManager that would also be acceptable.

Seth
  • 2,214
  • 1
  • 7
  • 21
jatinkumar patel
  • 2,920
  • 21
  • 28

1 Answers1

0

In MongoDB terms this is a $regex operation, so you issue in "raw" like this:

Abc.objects.raw_query({ "name.firstname": { "$regex": "j" } })

Note that the objects returned are not the model objects from your class definitions but simply raw python objects.

AnilRedshift
  • 7,937
  • 7
  • 35
  • 59
Blakes Seven
  • 49,422
  • 14
  • 129
  • 135