In MongoDB, query selectors (also called query operators) are special expressions used to filter and retrieve documents from a collection based on specific conditions. They allow you to perform complex searches, comparisons, and logical operations on your data.
$eq: Matches values that are equal to a specified value.
$gt: Matches values that are greater than a specified value.
$gte: Matches values that are greater than or equal to a specified value.
$in: Matches any of the values specified in an array.
$lt: Matches values that are less than a specified value.
$lte: Matches values that are less than or equal to a specified value.
$ne: Matches all values that are not equal to a specified value.
$nin: Matches none of the values specified in an array.
$and: Joins query clauses with a logical AND returns all documents that match the conditions of both clauses.
$not: Inverts the effect of a query predicate and returns documents that do not match the query predicate.
$nor: Joins query clauses with a logical NOR returns all documents that fail to match both clauses.
$or: Joins query clauses with a logical OR returns all documents that match the conditions of either clause.
$all: Matches arrays that contain all elements specified in the query.
$elemMatch: Selects documents if element in the array field matches all the specified $elemMatch conditions.
$size: Selects documents if the array field is a specified size.
$regex: Provides regular expression capabilities for pattern matching strings in queries.
$mod: Performs a modulo operation on the value of a field and selects documents with a specified result.
$text: Performs a text search on the content of the fields indexed with a text index. This is much more powerful than $regex for large blocks of text.
$expr: Allows the use of aggregation expressions within the query language. This is powerful because it lets you compare two different fields within the same document.
$jsonSchema: Validates documents against a given JSON Schema. While usually used for collection validation, it can be used in a query.
$where: Passes a string containing a JavaScript function or a full JavaScript function to the query system.
$bitsAllSet: Matches documents where all the bit positions specified in the query are set (1) in the document's field. Checking if a user has both Read and Write permissions.
$bitsAnySet: Matches documents where at least one of the specified bit positions is set (1). Checking if a user has either Admin OR Superuser status.
$bitsAllClear: Matches documents where all the bit positions specified are clear (0). Finding accounts that have no restrictions or blocks set.
$bitsAnyClear: Matches documents where at least one of the specified bit positions is clear (0). Finding items that are missing at least one required validation flag.