MongoEngine/mongoengine

distinct query doesn't obey _auto_dereference value set by no_dereference()

kottamakhil opened this issue · 0 comments

For example, suppose I have a collection of BlogPost documents, each of which has a user ReferenceField pointing to a User document. If I'd like to count the number of unique users who've written blog posts, I could do the following:

len(documents.BlogPost.objects(query).no_dereference().distinct("user"))

In this case, dereferencing all of those user fields just slows down the query as distinct doesn't obey the _auto_dereference field value set by the no_dereference() method.