किसी विशिष्ट गुण के आधार पर वस्तुओं की सूची प्रदर्शित करने के लिए, find() में डॉट नोटेशन का उपयोग करें। आइए दस्तावेजों के साथ एक संग्रह बनाएं -
> db.demo455.insertOne({"Information":{"Student":[{"Name":"Chris","Age":22}]}});{
"acknowledged" : true,
"insertedId" : ObjectId("5e7e1876dbcb9adb296c95c5")
}
> db.demo455.insertOne({"Information":{"Student":[{"Name":"David","Age":21}]}});{
"acknowledged" : true,
"insertedId" : ObjectId("5e7e1883dbcb9adb296c95c6")
}
> db.demo455.insertOne({"Information":{"Student":[{"Name":"Bob","Age":24}]}});{
"acknowledged" : true,
"insertedId" : ObjectId("5e7e188adbcb9adb296c95c7")
}
> db.demo455.insertOne({"Information":{"Student":[{"Name":"Robert","Age":21}]}});{
"acknowledged" : true,
"insertedId" : ObjectId("5e7e18bcdbcb9adb296c95c8")
} संग्रह से सभी दस्तावेज़ों को खोजने () विधि की सहायता से प्रदर्शित करें -
> db.demo455.find();
यह निम्नलिखित आउटपुट देगा -
{ "_id" : ObjectId("5e7e1876dbcb9adb296c95c5"), "Information" : { "Student" : [ { "Name" :
"Chris", "Age" : 22 } ] } }
{ "_id" : ObjectId("5e7e1883dbcb9adb296c95c6"), "Information" : { "Student" : [ { "Name" :
"David", "Age" : 21 } ] } }
{ "_id" : ObjectId("5e7e188adbcb9adb296c95c7"), "Information" : { "Student" : [ { "Name" :
"Bob", "Age" : 24 } ] } }
{ "_id" : ObjectId("5e7e18bcdbcb9adb296c95c8"), "Information" : { "Student" : [ { "Name" :
"Robert", "Age" : 21 } ] } } विशिष्ट गुण के आधार पर वस्तुओं की सूची प्रदर्शित करने के लिए निम्नलिखित क्वेरी है -
> db.demo455.find({"Information.Student.Age":21}); यह निम्नलिखित आउटपुट देगा -
{ "_id" : ObjectId("5e7e1883dbcb9adb296c95c6"), "Information" : { "Student" : [ { "Name" :
"David", "Age" : 21 } ] } }
{ "_id" : ObjectId("5e7e18bcdbcb9adb296c95c8"), "Information" : { "Student" : [ { "Name" :
"Robert", "Age" : 21 } ] } }