MongoDB −
-এ $বা প্রশ্নের জন্য সিনট্যাক্স নিম্নরূপdb.yourCollectionName.find({ $or : [ { "yourFieldName" : "yourValue1" }, {"yourFieldName":"yourValue2"},...........N ] } ).pretty();
ধারণাটি বুঝতে, আসুন ডকুমেন্টের সাথে একটি সংগ্রহ তৈরি করি। একটি নথির সাথে একটি সংগ্রহ তৈরি করার প্রশ্নটি নিম্নরূপ -
> db.orDemo.insertOne({"UserName":"Larry","UserAge":23}); { "acknowledged" : true, "insertedId" : ObjectId("5c9491fd4cf1f7a64fa4df4c") } > db.orDemo.insertOne({"UserName":"David","UserAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5c9492074cf1f7a64fa4df4d") } > db.orDemo.insertOne({"UserName":"Mike","UserAge":25}); { "acknowledged" : true, "insertedId" : ObjectId("5c94920e4cf1f7a64fa4df4e") } > db.orDemo.insertOne({"UserName":"Sam","UserAge":20}); { "acknowledged" : true, "insertedId" : ObjectId("5c9492144cf1f7a64fa4df4f") } > db.orDemo.insertOne({"UserName":"Carol","UserAge":24}); { "acknowledged" : true, "insertedId" : ObjectId("5c94921d4cf1f7a64fa4df50") } > db.orDemo.insertOne({"UserName":"Bob","UserAge":22}); { "acknowledged" : true, "insertedId" : ObjectId("5c94922c4cf1f7a64fa4df51") }
Find() পদ্ধতির সাহায্যে একটি সংগ্রহ থেকে সমস্ত নথি প্রদর্শন করুন। প্রশ্নটি নিম্নরূপ -
> db.orDemo.find().pretty();
নিম্নলিখিত আউটপুট:
{ "_id" : ObjectId("5c9491fd4cf1f7a64fa4df4c"), "UserName" : "Larry", "UserAge" : 23 } { "_id" : ObjectId("5c9492074cf1f7a64fa4df4d"), "UserName" : "David", "UserAge" : 21 } { "_id" : ObjectId("5c94920e4cf1f7a64fa4df4e"), "UserName" : "Mike", "UserAge" : 25 } { "_id" : ObjectId("5c9492144cf1f7a64fa4df4f"), "UserName" : "Sam", "UserAge" : 20 } { "_id" : ObjectId("5c94921d4cf1f7a64fa4df50"), "UserName" : "Carol", "UserAge" : 24 } { "_id" : ObjectId("5c94922c4cf1f7a64fa4df51"), "UserName" : "Bob", "UserAge" : 22 }
এখানে $or −
-এর জন্য প্রশ্ন আছে> db.orDemo.find({ $or : [ { "UserName" : "Carol" }, {"UserName":"Larry"} ] } ).pretty();
নিম্নলিখিত আউটপুট:
{ "_id" : ObjectId("5c9491fd4cf1f7a64fa4df4c"), "UserName" : "Larry", "UserAge" : 23 } { "_id" : ObjectId("5c94921d4cf1f7a64fa4df50"), "UserName" : "Carol", "UserAge" : 24 }