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 } find() 메서드를 사용하여 컬렉션의 모든 문서 표시 -
> db.demo467.find();
이것은 다음과 같은 출력을 생성합니다 -
{ "_id" : 101, "Information" : { "Name" : "Chris" } }
{ "_id" : 102, "Information" : { "Name" : "David" } } 다음은 Object −
에서 항목을 삭제하는 쿼리입니다.> db.demo467.update({_id:102},{$unset: {"Information.Name":1}},{multi: true});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) find() 메서드를 사용하여 컬렉션의 모든 문서 표시 -
> db.demo467.find();
이것은 다음과 같은 출력을 생성합니다 -
{ "_id" : 101, "Information" : { "Name" : "Chris" } }
{ "_id" : 102, "Information" : { } }