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
_idequal to1from alaric import AQ from alaric.comparison import EQ query = AQ(EQ("_id", 1))
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:
Lets match all documents where the field
counteris 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]))
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
prefixexistsfrom alaric import AQ from alaric.comparison import EXISTS query = AQ(EXISTS("prefix"))
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:
Lets match all documents where the field
counteris greater then 5.from alaric import AQ from alaric.comparison import GT query = AQ(GT("counter", 5))
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:
Lets match all documents where the field
counteris less then 5.from alaric import AQ from alaric.comparison import LT query = AQ(LT("counter", 5))
Regex¶
Also how to do full text searching.
- class alaric.comparison.Regex(field: str, regex: str, *, case_insensitive: bool = False, other_options: str = '')¶
Provides an interface for fetching data based on a given regex.
Let’s match all documents where the field
titlecontains the word “Blade”from alaric import AQ from alaric.comparison import Regex query = AQ(Regex("title", "Blade"))
For further options see: https://www.mongodb.com/docs/manual/reference/operator/query/regex/