Skip to content

Instantly share code, notes, and snippets.



Last active Jan 11, 2019
What would you like to do?
Mongoengine case insensitive query with _in operator
import operator
from functools import reduce
from mongoengine import Document, Q, StringField
class Person(Document):
name = StringField()
names = ['mike', 'John', 'JIMMY']
people = Person.objects(name__in=names) # Will only match the exact case
query = reduce(operator.or_, [Q(name__iexact=name) for name in names])
people = Person.objects(query) # Will ignore case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment