QuickDevGuide

Home › MongoDB

Query Operators & Projections — MongoDB

find(filter, projection) returns a cursor. Filters are documents built from operators. Category Operators Comparison $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin Logical $and (implicit with commas), $or, $nor, $not Element $exists, $type Array $all, $size, $elemMatch, plain value = "array contains" Evaluation $regex, $expr (compare fields), $text Cursor modifiers .sort({ price: -1 }), .skip(20), .limit(10), .count() → prefer countDocuments(filter). Projection { name: 1, price: 1, id: 0 } includes fields; { ratings: 0 } excludes. Use "field.sub": 1 for nested fields and $slice for arrays. Returning only what you need saves bandwidth and lets covered queries use indexes alone.

Key Takeaways