

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# \$1unset
<a name="unset-update"></a>

Amazon DocumentDB의 `$unset` 연산자는 문서에서 지정된 필드를 제거하는 데 사용됩니다. 를 사용하여 필드를 제거하면 문서에서 `$unset`필드가 삭제되고 그에 따라 문서 크기가 줄어듭니다. 이는 문서에서 불필요한 데이터를 제거하려는 경우에 유용할 수 있습니다.

**파라미터**
+ `field`: 문서에서 제거할 필드입니다. 이는 단일 필드이거나 중첩된 필드의 점선 경로일 수 있습니다.

## 예제(MongoDB 쉘)
<a name="unset-examples"></a>

다음 예제에서는 `$unset` 연산자를 사용하여 `example` 컬렉션의 문서에서 `Words` 필드를 제거하는 방법을 보여줍니다.

**샘플 문서 생성**

```
db.example.insert({
    "DocName": "Document 1",
    "Date": {
        "Month": 4,
        "Day": 18,
        "Year": 1987,
        "DoW": "Saturday"
    },
    "Words": 2482
})
```

**쿼리 예제**

```
db.example.update(
    { "DocName" : "Document 1" },
    { $unset: { Words:1 } }
)
```

**출력**

```
{
    "DocName": "Document 1",
    "Date": {
        "Month": 4,
        "Day": 18,
        "Year": 1987,
        "DoW": "Saturday"
    }
}
```

이 예제에서는 `$unset` 연산자를 사용하여 "문서 1"과 `DocName` 동일한 로 문서에서 `Words` 필드를 제거합니다. 결과 문서에는 더 이상 `Words` 필드가 포함되지 않습니다.

## 코드 예제
<a name="unset-code"></a>

`$unset` 명령을 사용하기 위한 코드 예제를 보려면 사용하려는 언어의 탭을 선택합니다.

------
#### [ Node.js ]

```
const { MongoClient } = require('mongodb');

async function removeField() {
  const client = await MongoClient.connect('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false');
  const db = client.db('test');
  const collection = db.collection('example');

  const result = await collection.updateOne(
    { "DocName": "Document 1" },
    { $unset: { "Words": 1 } }
  );

  console.log(`Modified ${result.modifiedCount} document(s)`);
  client.close();
}

removeField();
```

------
#### [ Python ]

```
from pymongo import MongoClient

def remove_field():
    client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false')
    db = client['test']
    collection = db['example']

    result = collection.update_one(
        {"DocName": "Document 1"},
        {"$unset": {"Words": 1}}
    )

    print(f"Modified {result.modified_count} document(s)")
    client.close()

remove_field()
```

------