In MongoDB, there are special query operators that allow for more specific and complex queries to be performed on collections. These operators are preceded by a dollar sign ($), and they can be used with query matchers to refine the results of a query. Here are some examples of MongoDB query operators:
1. $eq - matches documents where the value of a field equals a specified value.
Example: Find all documents where the name field equals "John".
ββ db.collection.find(name: $eq: "John") ββ
2. $ne - matches documents where the value of a field does not equal a specified value.
Example: Find all documents where the name field is not equal to "John".
ββ db.collection.find(name:$ne: "John") ββ
3. $gt/$gte - matches documents where the value of a field is greater than or greater than or equal to a specified value.
Example: Find all documents where the age field is greater than 30.
ββ db.collection.find(age:$gt: 30) ββ
4. $lt/$lte - matches documents where the value of a field is less than or less than or equal to a specified value.
Example: Find all documents where the age field is less than or equal to 30.
ββ db.collection.find(age:$lte: 30) ββ
5. $in - matches documents where the value of a field matches any value in a specified array.
Example: Find all documents where the name field is either "John" or "Jane".
ββ db.collection.find(name:$in: ["John", "Jane"]) ββ
6. $nin - matches documents where the value of a field does not match any value in a specified array.
Example: Find all documents where the name field is neither "John" nor "Jane".
ββ db.collection.find(name:$nin: ["John", "Jane"]) ββ
These are just a few examples of the MongoDB query operators available. There are many other operators that can be used to create more complex queries.