db.orders.find({ total: { $gte: 100, $lte: 500 } })Range filters are common for prices, scores, and timestamps.
Use filters, logical operators, projections, sorting, skip, and limit to shape query results efficiently.
Common selectors for exact matches and operator-based filtering.
db.orders.find({ total: { $gte: 100, $lte: 500 } })Range filters are common for prices, scores, and timestamps.
db.orders.find({ status: { $in: ["paid", "shipped"] } })Useful for dashboard queries and status subsets.
db.orders.find({ $or: [{ priority: "high" }, { total: { $gt: 1000 } }] })Logical operators help express more realistic query conditions.
db.orders.find({ shipped_at: { $exists: false } })Helpful when auditing incomplete data or backfills.
db.users.find({ email: /@example\.com$/i })Regex is flexible but can be expensive without the right patterns and indexes.
Return only the fields you need and keep results stable.
db.users.find({ active: true }, { name: 1, email: 1, _id: 0 })Projection can reduce payload size and improve clarity.
db.orders.find().sort({ created_at: -1 })`-1` is descending and `1` is ascending.
db.orders.find().sort({ created_at: -1 }).limit(20)Limit is a basic building block for API endpoints and dashboards.
db.orders.find().sort({ created_at: -1 }).skip(40).limit(20)Offset pagination is easy to understand but can become less efficient for very large offsets.
db.orders.find({ _id: { $lt: ObjectId("65f0c8d4d95f1b2a3c4d5e6f") } }).sort({ _id: -1 }).limit(20)Cursor pagination usually scales better than repeated large skips.