Query Operators ($eq $gt $lt $in) की जानकारी
dollar sign से शुरू होने वाले operators filters को सिर्फ equality match करने की बजाय values compare करने देते हैं।
In this page:
Syntax
db.collection_name.find({ field: { $gt: value } })
db.collection_name.find({ field: { $in: [value1, value2] } })
Query Operators ($eq $gt $lt $in)
$eq, $ne, $gt, $gte, $lt, और $lte values compare करते हैं, $in एक list में से कोई भी match करता है और $nin इनमें से कोई नहीं match करता। एक filter document में कई conditions AND से combine होते हैं। Range queries same field पर दो operators रखती हैं।
Note:
एक field के लिए कई operators एक object के अंदर रखें: { age: { $gte: 20, $lt: 40 } }।
उदाहरण: Query operators ($eq $gt $lt $in)
test> db.products.insertMany([
... { _id: 1, name: "Pen", price: 3 }, { _id: 2, name: "Book", price: 12 },
... { _id: 3, name: "Lamp", price: 45 }, { _id: 4, name: "Desk", price: 150 }
... ])
{
acknowledged: true,
insertedIds: { '0': 1, '1': 2, '2': 3, '3': 4 }
}
test> db.products.find({ price: { $gt: 10 } }, { _id: 0 })
[
{ name: 'Book', price: 12 },
{ name: 'Lamp', price: 45 },
{ name: 'Desk', price: 150 }
]
test> db.products.find({ price: { $gte: 10, $lt: 100 } }, { name: 1, _id: 0 })
[ { name: 'Book' }, { name: 'Lamp' } ]
test> db.products.find({ name: { $in: ["Pen", "Desk"] } }, { name: 1, price: 1, _id: 0 })
[ { name: 'Pen', price: 3 }, { name: 'Desk', price: 150 } ]
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- { age: > 30 } लिखना जो invalid है
- एक filter में एक field key दो बार repeat करना
- यह भूल जाना कि $in को एक array चाहिए
चैप्टर सारांश
- $eq $ne $gt $gte $lt $lte compare करते हैं
- $in और $nin lists test करते हैं
- कई conditions ANDed होते हैं
- Ranges एक field पर operators combine करती हैं
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: