# Query Operators — MongoDB

Source: https://www.geekswithgeeks.com/en/mongodb/mongo-query-operators

> Comparison and membership operators for precise filters.

## The common operators

`$eq`, `$ne`, `$gt`, `$gte`, `$lt`, `$lte` compare values; `$in` / `$nin` check membership in a list.

## $gt and $in in action

Operators go inside an object next to the field they apply to.

```javascript
db.products.find({ price: { $gt: 500 } })
db.products.find({ category: { $in: ["books", "toys"] } })
```

## Combining conditions

Multiple fields in one filter are implicitly ANDed. Use `$or` explicitly for alternatives.

```javascript
db.products.find({ price: { $lt: 100 }, inStock: true })
db.products.find({ $or: [{ price: { $lt: 100 } }, { featured: true }] })
```

**Quiz:** Which operator checks if a field's value is in a given list?

- [ ] $eq
- [x] $in
- [ ] $gt

*Answer:* $in. $in matches if the field's value equals any item in the array.
