If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
पिछले topic में आपने में $gt Operator के बारे में पढ़ा और समझा , इस topic में हम $lte
Operator के बारे में बात करेंगे।
MongoDB में $lte
का मतलब है less than or equals to (<=
) , जो एक comparison operator है , जो MongoDB queries में use होता है। इसका main use एक field की values को compare करके documents को filter करना है।
और less than or equals to (<=) का मतलब आप जानते हैं कि value या छोटी हो या बराबर।
{ field : { $lte : value } }
यहां , field
वो field / key है जिसकी value compare करनी है , और value
वो value है जिससे आप field / key की value के साथ compare करना चाहते हैं , यह check करेगा कि field की value दी गयी value से छोटी या बराबर है।
●●●
Suppose आपके database में एक students
नाम का collection है , जिसमे age , name , sex , marks और course fields हैं।
हम वो सभी students find करेंगे जिनका marks
50 या इससे कम है।
db.students.find({ "marks" : {$lte : 50} })
इस MongoDB query का SQL equivalent query कुछ इस तरह से होगी।
SELECT * FROM students WHERE marks <= 50;
ऊपर दिया गया example तो documents को find करने का था , हालाँकि same condition को update Query के साथ भी use कर सकते हैं।
db.students.updateOne( {"marks" : {$lte : 30} } , {"$set" : {"grade" : "D"} } )
SQL equivalent query
UPDATE students set grade='D' WHERE marks <= 30;
और इसी तरह से documents को delete भी कर सकते हैं।
// multiple delete db.students.deleteMany({"age" : {$lte : 18}}) // single delete db.students.deleteOne({"age" : {$lte : 18}})
SQL query
// multiple delete DELETE FROM students WHERE age <= 18; // single delete DELETE FROM students WHERE age <= 18 limit 1;
●●●
$lte
operator को आप Logical operators जैसे $and , $or या $in के साथ multi conditions के रूप में भी use कर सकते हैं।
1. नीचे दी गयी query में वो सभी documents retrieve किये गए हैं जहाँ status
active है और marks
70 या कम है।
db.students.find({ $and: [ { status: { $eq : "active" } }, { marks : { $lte : 70 } } ] })
SQL query
SELECT * FROM students WHERE status='active' AND marks <= 70;
2. $gt
operator example with $or operator
db.students.find({ $or: [ { age : { $lte : 25 } }, { marks: { $lte : 50} } ] })
SQL query
SELECT * FROM students WHERE age <=25 OR marks <= 50;
●●●
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook