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
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ụ
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"}
>
Last updated