Comparators#

This shows all the comparison objects and usages.

All of these classes are importable from alaric.comparison

Equality#

class alaric.comparison.EQ(field: str, value: int | str | float | bytes | dict | ObjectId)#

Asserts the provided field is equal to the provided value.

Parameters:

Notes

This also works on matching items in arrays in an OR based matching approach.

Lets match a document with an _id equal to 1

from alaric import AQ
from alaric.comparison import EQ

query = AQ(EQ("_id", 1))
build() Dict[str, Dict[str, int | str | float | bytes | dict | ObjectId]]#

Return this instance as a usable Mongo filter.

Contains#

class alaric.comparison.IN(field: str, value: list | tuple | set)#

Asserts the provided field is within the provided values.

This class can be used in conjunction with alaric.meta.NEGATE

Parameters:
  • field (str) – The field to check in.

  • value (Union[list, tuple, set]) – A iterable of values that field should be in.

Lets match all documents where the field counter is equal to any number in this list.

from alaric import AQ
from alaric.comparison import IN

query = AQ(IN("counter", [1, 3, 5, 7, 9]))
build() Dict[str, Dict[str, list | tuple | set]]#

Return this instance as a usable Mongo filter.

Existence#

Note

EXISTS is still exported for backwards compatibility reasons.

class alaric.comparison.Exists(field: str)#

Returns all documents that contain this field.

This class can be used in conjunction with NEGATE

Parameters:

field (str) – The field to check in.

Lets match all documents where the field prefix exists

from alaric import AQ
from alaric.comparison import EXISTS

query = AQ(EXISTS("prefix"))
build() Dict[str, Dict[str, int | str | float | bytes]]#

Return this instance as a usable Mongo filter.

Greater then#

class alaric.comparison.GT(field: str, value: int | str | float | bytes)#

Asserts the provided field is greater to the provided value.

This class can be used in conjunction with NEGATE

Parameters:
  • field (str) – The field to check in.

  • value (Union[int, str, float, bytes, dict]) – The value the field should be greater than.

Lets match all documents where the field counter is greater then 5.

from alaric import AQ
from alaric.comparison import GT

query = AQ(GT("counter", 5))
build() Dict[str, Dict[str, int | str | float | bytes]]#

Return this instance as a usable Mongo filter.

Less then#

class alaric.comparison.LT(field: str, value: int | str | float | bytes)#

Asserts the provided field is less to the provided value.

This class can be used in conjunction with NEGATE

Parameters:
  • field (str) – The field to check in.

  • value (Union[int, str, float, bytes, dict]) – The value the field should be less than.

Lets match all documents where the field counter is less then 5.

from alaric import AQ
from alaric.comparison import LT

query = AQ(LT("counter", 5))
build() Dict[str, Dict[str, int | str | float | bytes]]#

Return this instance as a usable Mongo filter.