Comparison Operators in MongoDB

From the MongoDB cheat sheet ยท Query Operators ยท verified Jul 2026

Comparison Operators

Compare field values in queries

javascript
// Equality
db.products.find({ price: 29.99 })
db.products.find({ category: { $eq: "electronics" } })

// Inequality
db.products.find({ price: { $ne: 0 } })

// Greater/Less than
db.products.find({ 
  price: { $gt: 20, $lte: 100 }  // 20 < price <= 100
})

// In/Not in array
db.products.find({ 
  category: { $in: ["electronics", "books"] }
})
db.products.find({ 
  status: { $nin: ["deleted", "archived"] }
})
๐ŸŸข Essential - Foundation of MongoDB queries
๐Ÿ’ก $eq is implicit when using key: value
๐Ÿ“Œ $in is like SQL IN operator
โšก Combine operators for complex queries
๐Ÿ”— Related: $exists, $type for field checks
queryoperatorscomparison

More MongoDB tasks

Back to the full MongoDB cheat sheet