সাবডকুমেন্ট মান অ্যাক্সেস করার জন্য, আসুন প্রথমে নথিগুলির সাথে একটি সংগ্রহ তৈরি করি -
> db.accessSubDocumentDemo.insertOne(
... {
...
... "Details" : {
... "1" : {
... "StudentLowerScore" : "33",
... "StudentHoghScore" : "55"
... },
... "2" : {
... "StudentLowerScore" : "45",
... "StudentHoghScore" : "65"
... },
... "3" : {
... "StudentLowerScore" : "39",
... "StudentHoghScore" : "91"
... },
... "4" : {
... "StudentLowerScore" : "41",
... "StudentHoghScore" : "85"
... }
... }
... }
... );
{
"acknowledged" : true,
"insertedId" : ObjectId("5cd3baf0edc6604c74817cd6")
} Find() পদ্ধতির সাহায্যে একটি সংগ্রহ থেকে সমস্ত নথি প্রদর্শন করার জন্য নিম্নলিখিত প্রশ্ন রয়েছে -
> db.accessSubDocumentDemo.find().pretty();
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{
"_id" : ObjectId("5cd3baf0edc6604c74817cd6"),
"Details" : {
"1" : {
"StudentLowerScore" : "33",
"StudentHoghScore" : "55"
},
"2" : {
"StudentLowerScore" : "45",
"StudentHoghScore" : "65"
},
"3" : {
"StudentLowerScore" : "39",
"StudentHoghScore" : "91"
},
"4" : {
"StudentLowerScore" : "41",
"StudentHoghScore" : "85"
}
}
} এখন, আমরা সাব ডকুমেন্টের মান অ্যাক্সেস করব যখন কীটি একটি সংখ্যা হবে:এখানে, সাব ডকুমেন্টটি 1 নম্বর সহ কী-এর জন্য অ্যাক্সেস করা হয় −
> db.accessSubDocumentDemo.findOne().Details["1"];
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{ "StudentLowerScore" : "33", "StudentHoghScore" : "55" }