MongoDB में शून्य मान क्वेरी करने के लिए, $ne ऑपरेटर का उपयोग करें। आइए पहले दस्तावेजों के साथ एक संग्रह बनाएं -
> db.queryingNullDemo.insertOne(
... {
... "StudentName":"Larry",
... "StudentDetails":
... {
... "StudentAge":21,
... "StudentSubject":"MongoDB"
... }
... }
... );
{
"acknowledged" : true,
"insertedId" : ObjectId("5cd00bec588d4a6447b2e05f")
}
> db.queryingNullDemo.insertOne(
... {
... "StudentName":"Sam",
... "StudentDetails":
... {
... "StudentAge":23,
... "StudentSubject":null
... }
... }
... );
{
"acknowledged" : true,
"insertedId" : ObjectId("5cd00c00588d4a6447b2e060")
} खोज () विधि की मदद से संग्रह से सभी दस्तावेजों को प्रदर्शित करने के लिए क्वेरी निम्नलिखित है -
> db.queryingNullDemo.find().pretty();
यह निम्नलिखित आउटपुट उत्पन्न करेगा -
{
"_id" : ObjectId("5cd00bec588d4a6447b2e05f"),
"StudentName" : "Larry",
"StudentDetails" : {
"StudentAge" : 21,
"StudentSubject" : "MongoDB"
}
}
{
"_id" : ObjectId("5cd00c00588d4a6447b2e060"),
"StudentName" : "Sam",
"StudentDetails" : {
"StudentAge" : 23,
"StudentSubject" : null
}
} निम्नलिखित है कि आप कैसे अशक्त के लिए क्वेरी कर सकते हैं -
> db.queryingNullDemo.find({'StudentDetails.StudentSubject': {$ne: null}}); यह निम्नलिखित आउटपुट उत्पन्न करेगा -
{ "_id" : ObjectId("5cd00bec588d4a6447b2e05f"),
"StudentName" : "Larry",
"StudentDetails" : { "StudentAge" : 21, "StudentSubject" : "MongoDB" } }