1

I need to make a query with a negation. In Django I would use exclude() but regarding to the MongoEngine doc exclude means something different.

Is there an query operator or a different function to make a negation?

Example:

MyClass.objects.exclude(attribute="test")
Ron
  • 22,128
  • 31
  • 108
  • 206

2 Answers2

5

You can negate other operators using not as an operator prefix:

not – negate a standard check, may be used before other operators (e.g. Q(age__not__mod=5))

(see MongoEngine's documentation).

This works in particular for string queries such as

Post.objects(title__not__contains='Test')

exclude filters attributes on the documents retrieved from the database (see documentation).

1

You can you negative operators like ne see http://mongoengine-odm.readthedocs.org/en/latest/guide/querying.html?highlight=ne

Ross
  • 17,861
  • 2
  • 55
  • 73