मान लें हमें specific value से greater value वाले document find करना है। इसके लिए nested document में dot notation का उपयोग करें और $gt से condition set करें।
Collection बनाना
> db.demo688.insert(
... {
... information:{id:1,details:[
... {otherDetails:{
... values:75
... }}
... ]}
... }
... )
WriteResult({ "nInserted" : 1 })
> db.demo688.insert({
... information:
... {
... id:2,
... details:
... [
... {otherDetails:{
... values:78
... }}
... ]
... }
... })
WriteResult({ "nInserted" : 1 })
सभी Documents Display करना
> db.demo688.find();
Output:
{ "_id" : ObjectId("5ea57986a7e81adc6a0b3965"), "information" : { "id" : 1, "details" : [ { "otherDetails" : { "values" : 75 } } ] } }
{ "_id" : ObjectId("5ea5799ca7e81adc6a0b3966"), "information" : { "id" : 2, "details" : [ { "otherDetails" : { "values" : 78 } } ] } }
Nested Document Access करने का Query
> db.demo688.find({"information.details.otherDetails.values":{$gt:75}});
Output:
{ "_id" : ObjectId("5ea5799ca7e81adc6a0b3966"), "information" : { "id" : 2, "details" : [ { "otherDetails" : { "values" : 78 } } ] } }
व्याख्या: Dot notation (information.details.otherDetails.values) से deeply nested field access किया। $gt: 75 से 75 से greater values वाले documents filter किए। केवल दूसरा document (values: 78) match हुआ।