আসুন আমরা নথি-
সহ একটি সংগ্রহ তৈরি করি> db.demo74.insertOne( ... { ... StudentName: "Chris", ... StudentDetails: [{ ... "Subject": "MongoDB", ... "isRegular": "Active" ... },{ ... "Subject": "MongoDB", ... "isRegular": "InActive" ... },{ ... "Subject": "MongoDB", ... "isRegular": "InActive" ... }] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e29c6b671bf0181ecc4226f") } > db.demo74.insertOne({ ... name: "document2", ... data: [{ ... "Subject": "MongoDB", ... "isRegular": "Active" ... },{ ... "Subject": "MongoDB", ... "isRegular": "Active" ... },{ ... "Subject": "MongoDB", ... "isRegular": "Active" ... }] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e29c6b771bf0181ecc42270") }
Find() পদ্ধতি -
এর সাহায্যে একটি সংগ্রহ থেকে সমস্ত নথি প্রদর্শন করুন> db.demo74.find();
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{ "_id" : ObjectId("5e29c6b671bf0181ecc4226f"), "StudentName" : "Chris", "StudentDetails" : [ { "Subject" : "MongoDB", "isRegular" : "Active" }, { "Subject" : "MongoDB", "isRegular" : "InActive" }, { "Subject" : "MongoDB", "isRegular" : "InActive" } ] } { "_id" : ObjectId("5e29c6b771bf0181ecc42270"), "name" : "document2", "data" : [ { "Subject" : "MongoDB", "isRegular" : "Active" }, { "Subject" : "MongoDB", "isRegular" : "Active" }, { "Subject" : "MongoDB", "isRegular" : "Active" } ] }
নিচে ডকুমেন্ট খোঁজার জন্য ক্যোয়ারী দেওয়া হল যেখানে অ্যারের সমস্ত বস্তুর নির্দিষ্ট মান আছে −
> db.demo74.find({ " StudentDetails": { "$not": { "$elemMatch": { "isRegular": { $ne: "Active" } } } }, "StudentDetails.isRegular": "Active" }).pretty();
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{ "_id" : ObjectId("5e29c6b671bf0181ecc4226f"), "StudentName" : "Chris", "StudentDetails" : [ { "Subject" : "MongoDB", "isRegular" : "Active" }, { "Subject" : "MongoDB", "isRegular" : "InActive" }, { "Subject" : "MongoDB", "isRegular" : "InActive" } ] }