MongoDB $eq Operator In Hindi | $eq operator in MongoDB In Hindi

📔 : MongoDB 🔗

पिछले topics में दिए गए कई examples में $eq Operator का use देखा होगा , इस topic में हम $eq Operator के बारे में अच्छे से समझेंगे।

What is $eq operator in MongoDB ?

$eq का मतलब है equals to (=) , और MongoDB में $eq operator एक query operator है जो एक field की value को एक specific दी गयी user value के साथ compare करने के लिए use होता है।

$eq operator का use documents को filter करने के लिए किया जाता है जिससे हम documents को find , update या delete कर सकते हैं।

MongoDB $eq Syntax

{ field: { $eq: value } }

यहां , field वो field / key है जिसकी value compare करनी है और value वो value है जिससे आप field / key की value के साथ compare करना चाहते हैं। $eq operator का use equality condition check करने के लिए किया जाता है।

MongoDB $eq Example

Suppose आपके database में एक students नाम का collection है , जिसमे age , name , sex और course fields हैं।

सभी Male students को find करने के लिए query कुछ इस तरह से होगी -

db.students.find({
"gender" : {$eq : "Male"}
})

ऊपर दी गयी MongoDB query का SQL equivalent query कुछ इस तरह से होगी।

SELECT *
FROM students
WHERE sex = "Male";

shell में find() method by default documents को non-structured format में show करता है इसलिए formatted way में documents को show करने के लिए आप pretty() method का use कर सकते हैं

db.students.find({
"gender" : {$e : "Male"}
}).pretty()

Use other operator with $eq in MongoDB

$eq operator को आप Logical operators जैसे $and , $or या $in के साथ multi conditions के रूप में भी use कर सकते हैं।

1. नीचे दी गयी query में वो सभी documents retrieve किये गए हैं जहाँ 'status' = "active" है और 'category' = "electronics" है।

db.students.find({
  $and: [
    { status: { $eq: "active" } },
    { category: { $eq: "electronics" } }
  ]
}
)

2. $eq operator example with $or operator

db.students.find({
  $or: [
    { age: { $eq: 25 } },
    { age: { $eq: 30 } }
  ]
})

3. $eq operator example with $not operator

db.students.find({
  name: { $not: { $eq: "John" } }
})

तो कुछ इस तरह से MongoDB में $eq operator का use किया जाता है , हालाँकि इसका use advance label पर भी होता है जिसे हम आगे सीखेंगे।

बाकी आप same conditions का use करके documents को update और delete कर सकते हैं।

Related Topics :

Rahul Kumar

Rahul Kumar

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

b2eprogrammers