Q9: Explain fundamental comparison operators in MongoDB ($eq, $gt, $in, $nin).

Comparison operators match field values against criteria:

  • $gt / $gte: Greater than / Greater than or equal to.
  • $lt / $lte: Less than / Less than or equal to.
  • $in: Matches any value specified in an array status: { $in: ['active', 'pending'] }.
  • $nin: Matches values not present in the specified array.
Key Takeaways
  • $in evaluates array matches in a single query pass.

  • Combine operators for bounded range searches { age: { $gte: 18, $lte: 65 } }.

Knowledge Check

Which operator finds documents where a status field equals EITHER 'active' OR 'verified'?