MongoDB-এ অর্ডER বিবেচনা না করে অ্যারে একজাক্ট ম্যাচ করতে $all অপারেটর সহ $size ব্যবহার করা হয়।
ডেমো কলেকশন তৈরি
> db.exactMatchArrayDemo.insertOne({"StudentName":"David","StudentAge":22,"StudentGameScores":[45,78,98]});
{ "acknowledged" : true, "insertedId" : ObjectId("5c9c94702d6669774125246c") }
> db.exactMatchArrayDemo.insertOne({"StudentName":"Chris","StudentAge":23,"StudentGameScores":[45,78]});
{ "acknowledged" : true, "insertedId" : ObjectId("5c9c94a42d6669774125246d") }
সকল ডকুমেন্ট দেখা
> db.exactMatchArrayDemo.find().pretty();
আউটপুট
{ "_id" : ObjectId("5c9c94702d6669774125246c"), "StudentName" : "David", "StudentAge" : 22, "StudentGameScores" : [ 45, 78, 98 ] }
{ "_id" : ObjectId("5c9c94a42d6669774125246d"), "StudentName" : "Chris", "StudentAge" : 23, "StudentGameScores" : [ 45, 78 ] }
সাইজ ২ এবং [78, 45] মান সমন্বিত অ্যারে খোঁজা
> db.exactMatchArrayDemo.find({ "StudentGameScores": { "$size" : 2, "$all": [ 78, 45 ] } }).pretty();
আউটপুট
সাইজ ৩ এবং [78, 45] মান সমন্বিত অ্যারে খোঁজা
> db.exactMatchArrayDemo.find({ "StudentGameScores": { "$size" : 3, "$all": [ 78, 45 ] } }).pretty();আউটপুট
মূল নীতি
$all- নির্দিষ্ট সকল এলিমেন্ট অ্যারেতে থাকতে হবে$size- অ্যারের আকার নিশ্চিত করে- দুটি মিলিয়ে অর্ডার-নিরপেক্ষ একজাক্ট ম্যাচ করা যায়