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.