QueryOperator

class QueryOperator(value, requires_sync=True)

QueryOperators can be used to automatically generate queries that are understood by mongo. Each of the operators can be used as defined in the mongo manual as they’re just a direct mapping. See BaseDocument to use it with querying methods like get_objects().

Note

Please note that because of the overlap in keywords all these classes are capitalised!

Eq

class Eq(value, requires_sync=True)

Checks for any value that is equal to the given value. Not using it is the default case and functionally the same as just leaving out a QueryOperator completely.

Example usage:

>>> await Document.get_objects(num=5)
>>> await Document.get_objects(num=Eq(5))

Query:

>>> Eq(5)()
{'$eq': 5}

Ne

class Ne(value, requires_sync=True)

Checks for any value that is not equal to the given value.

Example usage:

>>> await Document.get_objects(num=Ne(5))

Query:

>>> Ne(5)()
{'$ne': 5}

Lt

class Lt(value, requires_sync=True)

Checks for any value that is lesser than the given value.

Example usage:

>>> await Document.get_objects(num=Lt(5))

Query:

>>> Lt(5)()
{'$lt': 5}

Lte

class Lte(value, requires_sync=True)

Checks for any value that is lesser than or equal to the given value.

Example usage:

>>> await Document.get_objects(num=Lte(5))

Query:

>>> Lte(5)()
{'$lte': 5}

Gt

class Gt(value, requires_sync=True)

Checks for any value that is greater than the given value.

Example usage:

>>> await Document.get_objects(num=Gt(5))

Query:

>>> Gt(5)()
{'$gt': 5}

Gte

class Gte(value, requires_sync=True)

Checks for any value that is greater than or equal to the given value.

Example usage:

>>> await Document.get_objects(num=Gte(5))

Query:

>>> Gte(5)()
{'$gte': 5}

In

class In(value, requires_sync=True)

Checks for any value that is included in the given value.

Example usage:

>>> await Document.get_objects(num=In([1, 4, 5]))

Query:

>>> In([1, 4, 5])()
{'$in': [1, 4, 5]}

Nin

class Nin(value, requires_sync=True)

Checks for any value that is not included in the given value.

Example usage:

>>> await Document.get_objects(num=Nin([1, 4, 5]))

Query:

>>> Nin([1, 4, 5])()
{'$nin': [1, 4, 5]}