MongoDB-তে একটি নেস্টেড অবজেক্ট পুনরুদ্ধার করতে, $ অপারেটর ব্যবহার করুন। আসুন প্রথমে নথি-
সহ একটি সংগ্রহ তৈরি করি> db.queryNestedObject.insertOne(
... {
... "StudentName" : "James",
... "StudentSubjectScore" : [
... {"StudentMongoDBScore":98},
... {"StudentCScore":92},
... {"StudentJavaScore":91}
... ]
... }
... );
{
"acknowledged" : true,
"insertedId" : ObjectId("5ccf49a9dceb9a92e6aa1962")
} Find() পদ্ধতির সাহায্যে একটি সংগ্রহ থেকে সমস্ত নথি প্রদর্শন করার জন্য নিম্নলিখিত প্রশ্ন রয়েছে -
> db.queryNestedObject.find().pretty();
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{
"_id" : ObjectId("5ccf49a9dceb9a92e6aa1962"),
"StudentName" : "James",
"StudentSubjectScore" : [
{
"StudentMongoDBScore" : 98
},
{
"StudentCScore" : 92
},
{
"StudentJavaScore" : 91
}
]
} একটি নেস্টেড অবজেক্ট −
পুনরুদ্ধার করার জন্য নিম্নোক্ত ক্যোয়ারী> db.queryNestedObject.find({'StudentSubjectScore.StudentJavaScore' : 91},{'StudentSubjectScore.$': 1 , _id: 0}); এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{ "StudentSubjectScore" : [ { "StudentJavaScore" : 91 } ] }