এই জন্য, আপনি MongoDB এ aggregate() ব্যবহার করতে পারেন। আসুন নথি-
সহ একটি সংগ্রহ তৈরি করি> db.demo149.insertOne({"Status":40}); { "acknowledged" : true, "insertedId" : ObjectId("5e350386fdf09dd6d08539c4") } > db.demo149.insertOne({"Status":40}); { "acknowledged" : true, "insertedId" : ObjectId("5e350388fdf09dd6d08539c5") } > db.demo149.insertOne({"Status":50}); { "acknowledged" : true, "insertedId" : ObjectId("5e35038afdf09dd6d08539c6") }
Find() পদ্ধতি -
এর সাহায্যে একটি সংগ্রহ থেকে সমস্ত নথি প্রদর্শন করুন> db.demo149.find();
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{ "_id" : ObjectId("5e350386fdf09dd6d08539c4"), "Status" : 40 } { "_id" : ObjectId("5e350388fdf09dd6d08539c5"), "Status" : 40 } { "_id" : ObjectId("5e35038afdf09dd6d08539c6"), "Status" : 50 }
এখানে −
দ্বারা MongoDB গ্রুপের প্রশ্ন রয়েছে> db.demo149.aggregate([ ... { ... "$group": { ... "_id": null, ... "done": { ... "$push": { ... "$cond": [ ... { "$eq": [ "$Status", 40 ] }, ... { "_id": "$_id", "Status": "$Status" }, ... false ... ] ... } ... }, ... "notdone": { ... "$push": { ... "$cond": [ ... { "$eq": [ "$Status", 50 ] }, ... { "_id": "$_id", "Status": "$Status" }, ... false ... ] ... } ... } ... } ... }, ... { ... "$project": { ... "_id": 0, ... "done": { ... "$setDifference": [ "$done", [false] ] ... }, ... "notdone": { ... "$setDifference": [ "$notdone", [false] ] ... } ... } ... } ... ]);
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{ "done" : [ { "_id" : ObjectId("5e350386fdf09dd6d08539c4"), "Status" : 40 }, { "_id" : ObjectId("5e350388fdf09dd6d08539c5"), "Status" : 40 } ], "notdone" : [ { "_id" : ObjectId("5e35038afdf09dd6d08539c6"), "Status" : 50 } ] }