Question

I am trying to build a query which returns all the objects that have a certain email address in their ListField(EmailField()).

I tried with mongoengine by executing

User.Objects.filter(emaillist__contains=email)

The problem is when the emailstring is a substring of an email contained in emaillist, the object is returned as well. However I only want it to be returned when the entire case insensitive emailstring is contained in the Listfield.

Is this possible somehow or by executing a raw query? Any hints or help is much appreciated!

Jonas

Was it helpful?

Solution

In the documentation they have this model, similar to your emaillist:

class Post(Document):
    tags = ListField(StringField(max_length=30))

And they query like this:

for post in Post.objects(tags='mongodb'):
    print post.title

So your query should work like this (with the case insensitivity):

User.Objects.filter(emaillist__iexact=email)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top