MongoDB में JSON सरणी के आंतरिक तत्व तक पहुंचने के लिए डॉट नोटेशन का उपयोग करें। आइए एक कलेक्शन बनाते हैं:
> db.demo687.insert({CountryName:'US', info: { id:101, details: [ { Name:'Chris', SubjectName:'MongoDB', otherDetails:{ "Marks":58, Age:23 } } ] } } )
WriteResult({ "nInserted" : 1 })
> db.demo687.insert({CountryName:'UK', info: { id:102, details: [ { Name:'David', SubjectName:'MySQL', otherDetails:{ "Marks":78, Age:21 } } ] } } )
WriteResult({ "nInserted" : 1 })
find() से सभी डॉक्यूमेंट्स देखें:
> db.demo687.find();
आउटपुट:
{ "_id" : ObjectId("5ea55658a7e81adc6a0b3962"), "CountryName" : "US", "info" : { "id" : 101, "details" : [ { "Name" : "Chris", "SubjectName" : "MongoDB", "otherDetails" : { "Marks" : 58, "Age" : 23 } } ] } }
{ "_id" : ObjectId("5ea55673a7e81adc6a0b3963"), "CountryName" : "UK", "info" : { "id" : 102, "details" : [ { "Name" : "David", "SubjectName" : "MySQL", "otherDetails" : { "Marks" : 78, "Age" : 21 } } ] } }
JSON सरणी के आंतरिक तत्व तक पहुंचने के लिए क्वेरी:
> db.demo687.find({"info.details.otherDetails.Marks":58});
परिणाम:
{ "_id" : ObjectId("5ea55658a7e81adc6a0b3962"), "CountryName" : "US", "info" : { "id" : 101, "details" : [ { "Name" : "Chris", "SubjectName" : "MongoDB", "otherDetails" : { "Marks" : 58, "Age" : 23 } } ] } }