एकाधिक क्षेत्रों के अस्तित्व की जांच करने के लिए, $ और $ के साथ मौजूद $ का उपयोग करें। आइए दस्तावेजों के साथ एक संग्रह बनाएं -
> db.demo475.insertOne({"StudentFirstName":"Chris","StudentAge":23});{
"acknowledged" : true,
"insertedId" : ObjectId("5e80c113b0f3fa88e2279088")
}
>
db.demo475.insertOne({"StudentFirstName":"Bob","StudentAge":21,"StudentCountryName":"US"});{
"acknowledged" : true,
"insertedId" : ObjectId("5e80c127b0f3fa88e2279089")
}
> db.demo475.insertOne({"StudentFirstName":"David","StudentAge":22});{
"acknowledged" : true,
"insertedId" : ObjectId("5e80c135b0f3fa88e227908a")
} संग्रह से सभी दस्तावेज़ों को खोजने () विधि की सहायता से प्रदर्शित करें -
> db.demo475.find();
यह निम्नलिखित आउटपुट देगा -
{ "_id" : ObjectId("5e80c113b0f3fa88e2279088"), "StudentFirstName" : "Chris", "StudentAge" :
23 }
{ "_id" : ObjectId("5e80c127b0f3fa88e2279089"), "StudentFirstName" : "Bob", "StudentAge" :
21, "StudentCountryName" : "US" }
{ "_id" : ObjectId("5e80c135b0f3fa88e227908a"), "StudentFirstName" : "David", "StudentAge"
: 22 } कई क्षेत्रों के अस्तित्व की जांच करने के लिए निम्नलिखित क्वेरी है -
> db.demo475.find(
... { '$and':
... [ { 'StudentFirstName': { '$exists': true } },
... { 'StudentAge': { '$exists': true } },
... { 'StudentCountryName': { '$exists': true } } ]
... }
... ); यह निम्नलिखित आउटपुट देगा -
{ "_id" : ObjectId("5e80c127b0f3fa88e2279089"), "StudentFirstName" : "Bob", "StudentAge" :
21, "StudentCountryName" : "US" }