नेस्टेड दस्तावेज़ों के लिए ऑब्जेक्ट्स की एक सरणी पर क्वेरी करने के लिए, ढूंढें () का उपयोग करें। आइए दस्तावेजों के साथ एक संग्रह बनाएं -
> db.demo763.insertOne(
... {
... _id:1,
... CountryName:"US",
... "studentInformation": [
... {
... StudentName:"Chris",
... },
... {
... StudentName:"David",
... StudentAge:22
... }
... ]
... }
... );
{ "acknowledged" : true, "insertedId" : 1 } संग्रह से सभी दस्तावेज़ों को खोजने () विधि की सहायता से प्रदर्शित करें -
> db.demo763.find();
यह निम्नलिखित आउटपुट देगा -
{ "_id" : 1, "CountryName" : "US", "studentInformation" : [ { "StudentName" : "Chris" }, { "StudentName" : "David", "StudentAge" : 22 } ] } विशिष्ट नेस्टेड दस्तावेज़ प्राप्त करने के लिए ऑब्जेक्ट्स की एक सरणी को क्वेरी करने का तरीका निम्नलिखित है -
> db.demo763.find({},
... {
... studentInformation: {
... $elemMatch: {
... StudentAge: {
... $exists: true
... }
... }
... }
... }) यह निम्नलिखित आउटपुट देगा -
{ "_id" : 1, "studentInformation" : [ { "StudentName" : "David", "StudentAge" : 22 } ] }