एकाधिक फ़ील्ड के अस्तित्व की जांच के लिए $exists के साथ $and ऑपरेटर का उपयोग करें। आइए दस्तावेज़ों के साथ एक संग्रह बनाएं:
> 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" }