आइए दस्तावेजों के साथ एक कलेक्शन बनाते हैं:
> db.demo575.insertOne({id:101,Information:{Name:"Chris",Age:21}}); { "acknowledged" : true, "insertedId" : ObjectId("5e916a55581e9acd78b427f7") }
> db.demo575.insertOne({id:102,Information:{Name:"David",Age:20}}); { "acknowledged" : true, "insertedId" : ObjectId("5e916a5f581e9acd78b427f8") }
> db.demo575.insertOne({id:101,Information:{Name:"Bob",Age:23}}); { "acknowledged" : true, "insertedId" : ObjectId("5e916a67581e9acd78b427f9") }
find() मेथड की मदद से कलेक्शन के सभी दस्तावेज प्रदर्शित करें:
> db.demo575.find();
यह निम्न आउटपुट देगा:
{ "_id" : ObjectId("5e916a55581e9acd78b427f7"), "id" : 101, "Information" : { "Name" : "Chris", "Age" : 21 } }
{ "_id" : ObjectId("5e916a5f581e9acd78b427f8"), "id" : 102, "Information" : { "Name" : "David", "Age" : 20 } }
{ "_id" : ObjectId("5e916a67581e9acd78b427f9"), "id" : 101, "Information" : { "Name" : "Bob", "Age" : 23 } }
_id फील्ड को छिपाकर बाकी प्रदर्शित करने के लिए क्वेरी:
> db.demo575.find({id:101},{"Information.Name":1});
यह निम्न आउटपुट देगा:
{ "_id" : ObjectId("5e916a55581e9acd78b427f7"), "Information" : { "Name" : "Chris" } }
{ "_id" : ObjectId("5e916a67581e9acd78b427f9"), "Information" : { "Name" : "Bob" } }