MongoDB में ऑब्जेक्ट से आइटम हटाने के लिए $unset ऑपरेटर का उपयोग करें। आइए दस्तावेज़ों के साथ एक संग्रह बनाएं:
> db.demo467.insertOne( ... { ... _id:101, ... "Information":{"Name":"Chris"} ... } ... ); { "acknowledged" : true, "insertedId" : 101 } > db.demo467.insertOne( ... { ... _id:102, ... "Information":{"Name":"David"} ... } ... ); { "acknowledged" : true, "insertedId" : 102 }
सभी दस्तावेज़ प्रदर्शित करें
> db.demo467.find();
आउटपुट:
{ "_id" : 101, "Information" : { "Name" : "Chris" } } { "_id" : 102, "Information" : { "Name" : "David" } }
ऑब्जेक्ट से आइटम हटाने की क्वेरी
> db.demo467.update({_id:102},{$unset: {"Information.Name":1}},{multi: true}); WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
हटाने के बाद सभी दस्तावेज़ प्रदर्शित करें
> db.demo467.find();
आउटपुट:
{ "_id" : 101, "Information" : { "Name" : "Chris" } } { "_id" : 102, "Information" : { } }