Skip to main content

Operators

Operators are used to connect operands or parameters and return results. In terms of syntax, operators can appear before, after, or between operands.

Operator examples

Data filtering (where)

Equal to

Use $eq to indicate equal to, as shown in the following example:

where={"category": {"$eq": "AI"}}

Not equal to

Use $ne to indicate not equal to, as shown in the following example:

where={"status": {"$ne": "deleted"}}

Greater than

Use $gt to indicate greater than, as shown in the following example:

where={"score": {"$gt": 90}}

Greater than or equal to

Use $gte to indicate greater than or equal to, as shown in the following example:

where={"score": {"$gte": 90}}

Less than

Use $lt to indicate less than, as shown in the following example:

where={"score": {"$lt": 50}}

Less than or equal to

Use $lte to indicate less than or equal to, as shown in the following example:

where={"score": {"$lte": 50}}

Contains

Use $in to indicate contains, as shown in the following example:

where={"tag": {"$in": ["ml", "python", "ai"]}}

Does not contain

Use $nin to indicate does not contain, as shown in the following example:

where={"tag": {"$nin": ["deprecated", "old"]}}

Logical OR

Use $or to indicate logical OR, as shown in the following example:

where={
"$or": [
{"category": {"$eq": "AI"}},
{"tag": {"$eq": "python"}}
]
}

Logical AND

Use $and to indicate logical AND, as shown in the following example:

where={
"$and": [
{"category": {"$eq": "AI"}},
{"score": {"$gte": 90}}
]
}

Text filtering (where_document)

Full-text search (contains substring)

Use $contains to indicate full-text search, as shown in the following example:

where_document={"$contains": "machine learning"}

Regular expression

Use $regex to indicate regular expression, as shown in the following example:

where_document={"$regex": "pattern.*"}

Logical OR

Use $or to indicate logical OR, as shown in the following example:

where_document={
"$or": [
{"$contains": "machine learning"},
{"$contains": "artificial intelligence"}
]
}

Logical AND

Use $and to indicate logical AND, as shown in the following example:

where_document={
"$and": [
{"$contains": "machine"},
{"$contains": "learning"}
]
}