Trong mongoose, chúng tôi có thể kiểm tra xem thao tác cập nhật đã sửa đổi tài liệu hay chưa bằng model.update()
:
model.update(query, update, function(err, raw){
if (raw.nModified >= 1) console.log('document is modified!')
});
Có cách nào để làm điều tương tự với model.findOneAndUpdate()
?
model.findOneAndUpdate(query, update, { new: true }, function(err, doc){
if (doc) {
// So MongoDB found the document, but is there a way
// to know the document was indeed modified?
}
});