1

I am using django-mongodb-engine

Here is used mondodbmanager to use 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'})**

This is not working as expect. So how can i use contains lookup type on embedded fields?

If there is other workaround except then mongodbmanager will be also acceptable like below.

from django_mongodb_engine.query import A
Abc.objects.filter(name=A('first_name__icontains','j'))
4

1 回答 1

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.

于 2015-07-14T10:50:22.320 回答