update()与findOneAndUpdate()有何差别?
-
update()与findOneAndUpdate()有何差别?
-
update(): Is meant to perform an atomic update operation against "one or more" documents matched by it's query condition in a collection. It returns the number of modified documents in it's response.
findOneAndUpdate(): Has the purpose of both processing an update statment on a "singular" document, as well as retrieving the content of that "singular" document. The state returned depends on the value of the "new" option as passed to the operation. Where
true
the "modified" document is returned. Wherefalse
the "original" document is returned before any modification. The latter form is the default option.
· update()返回資料處理條數
· findOneAndUpdate()返回處理後的資料
· 簡單來說,你需要獲取資料就用findOneAndUpdate(),只需要修改資料而不關注修改後資料那就用update()。
文章來源:
本帖下載内容已隐藏,请登入以查看隐藏内容!