একটি কালেকশন তৈরি করি:
>db.demo419.insertOne({"ProductInformation":[{"ProductName":"Product-1","ProductPrice":500},{"ProductName":"Product-2","ProductPrice":600}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e724762b912067e57771ae8") } find() মেথড দিয়ে সব ডকুমেন্ট দেখান:
> db.demo419.find();
আউটপুট:
{ "_id" : ObjectId("5e724762b912067e57771ae8"), "ProductInformation" : [ { "ProductName" : "Product-1", "ProductPrice" : 500 }, { "ProductName" : "Product-2", "ProductPrice" : 600 } ] } নির্দিষ্ট কী দিয়ে অ্যারেতে অবজেক্ট আপডেট করার কোয়ারি:
> db.demo419.update({'ProductInformation.ProductName' : "Product-1" }, { $set : { 'ProductInformation.$.ProductPrice' : 1250}}); WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 } আবার find() মেথড দিয়ে দেখান:
> db.demo419.find();
আউটপুট:
{ "_id" : ObjectId("5e724762b912067e57771ae8"), "ProductInformation" : [ { "ProductName" : "Product-1", "ProductPrice" : 1250 }, { "ProductName" : "Product-2", "ProductPrice" : 600 } ]