> For the complete documentation index, see [llms.txt](https://janeto.gitbook.io/mongodb-toan-tap/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://janeto.gitbook.io/mongodb-toan-tap/cap-nhat-document-trong-mongodb/phuong-thuc-save-trong-mongodb.md).

# Phương thức save() trong MongoDB

Phương thức save() thay thế Document đang tồn tại với Document mới đã được truyền trong phương thức save() này.

## Cú pháp <a href="#c-ph-p" id="c-ph-p"></a>

Cú pháp cơ bản của phương thức save() như sau:

```
>db.COLLECTION_NAME.save({_id:ObjectId(),NEW_DATA})
```

## Ví dụ <a href="#v-d" id="v-d"></a>

Ví dụ sau sẽ thay thế Document với \_id là '5983548781331adf45ec7'.

```
>db.mycol.save(

{
"_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point New Topic", "by":"Tutorials Point"
}

)
```

```
>db.mycol.find()

{ "_id" : ObjectId(5983548781331adf45ec5), "title":"Tutorials Point New Topic", "by":"Tutorials Point"}

{ "_id" : ObjectId(5983548781331adf45ec6), "title":"NoSQL Overview"}

{ "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point Overview"}

>
```
