ডট (.) নোটেশন ব্যবহার করে নেস্টেড অ্যারে কুয়েরি
MongoDB-এ গভীরভাবে নেস্টেড অ্যারেতে অবস্থিত নির্দিষ্ট এলিমেন্ট বের করতে ডট নোটেশন ব্যবহার করা হয়।
নমুনা ডকুমেন্ট ইনসার্ট
> db.extractParticularElementDemo.insertOne(
{
"_id" : 101,
"StudentName" : "John",
"StudentInformation" : [
{
"Age" : 21,
"StudentPersonalInformation" : [
{
"StudentNickName" : "Mike",
"StudentFamilyDetails" : [
{ "FatherName" : "Carol" }
]
},
{
"StudentAnotherName" : "David",
"StudentFamilyDetails" : [
{ "FatherName" : "Robert" }
]
}
]
}
]
}
);
{ "acknowledged" : true, "insertedId" : 101 }
সব ডকুমেন্ট দেখানো
> db.extractParticularElementDemo.find().pretty();
নেস্টেড অ্যারে থেকে নির্দিষ্ট এলিমেন্ট বের করার কুয়েরি
FatherName ফিল্ড "Carol" হলে সেটি বের করতে:
> db.extractParticularElementDemo.find(
{'StudentInformation.StudentPersonalInformation.StudentFamilyDetails.FatherName':'Carol'},
{'StudentInformation.StudentPersonalInformation.StudentFamilyDetails.FatherName':1,"_id":0}
).pretty();
আউটপুট:
{
"StudentInformation" : [
{
"StudentPersonalInformation" : [
{
"StudentFamilyDetails" : [
{ "FatherName" : "Carol" }
]
},
{
"StudentFamilyDetails" : [
{ "FatherName" : "Robert" }
]
}
]
}
]
}
টিপ: প্রজেকশনে 1 দিয়ে শুধু আপনার প্রয়োজনীয় ফিল্ডগুলো রিটার্ন করানো যায়।