আসুন প্রথমে নথি-
সহ একটি সংগ্রহ তৈরি করি> db.demo389.insertOne( ... { ... "details":[ ... { ... "Name":[ ... "Chris", ... "David" ... ] ... }, ... { ... "Name":[ ... "Bob", ... "Mike" ... ] ... }, ... { ... "Name":[ ... "Carol", ... "Sam" ... ] ... }, ... { ... "Name":[ ... "David", ... "John" ... ] ... } ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e5d1d8f22064be7ab44e7f9") }
Find() পদ্ধতি -
এর সাহায্যে একটি সংগ্রহ থেকে সমস্ত নথি প্রদর্শন করুন> db.demo389.find();
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{ "_id" : ObjectId("5e5d1d8f22064be7ab44e7f9"), "details" : [ { "Name" : [ "Chris", "David" ] }, { "Name" : [ "Bob", "Mike" ] }, { "Name" : [ "Carol", "Sam" ] }, { "Name" : [ "David", "John" ] } ] }
নিম্নে সমস্ত মান −
বের করার জন্য ক্যোয়ারী দেওয়া হল> db.demo389.aggregate([ ... { ... $unwind: "$details" ... }, ... { ... $unwind: "$details.Name" ... }, ... { ... $project: { ... "_id": "$_id", ... "Name": "$details.Name" ... } ... }, ... { ... $group: { ... _id: "_id", ... out: { ... $push: "$Name" ... } ... } ... }, ... { ... $project: { ... "_id": 0, ... "NameArray": "$out" ... } ... } ... ])
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{ "NameArray" : [ "Chris", "David", "Bob", "Mike", "Carol", "Sam", "David", "John" ] }