mongoose 全量更新

mongoose文檔

Note:

All top level keys which are not atomic operation names are treated as set operations:

Example:
var query = { name: 'borne' };
Model.update(query, { name: 'jason bourne' }, options, callback)

// is sent as
Model.update(query, { $set: { name: 'jason bourne' }}, options, callback)
// if overwrite option is false. If overwrite is true, sent without the $set wrapper.

This helps prevent accidentally overwriting all documents in your collection with { name: ‘jason bourne’ }.
目的是好的,防止覆寫
但有些時候我確實想全量直接覆蓋

參考內容

github issue

https://github.com/Automattic/mongoose/issues/2144
還沒有文檔化。。。

mongoose 源碼中

這裏寫圖片描述
是存在這個參數可以覆蓋更新的,只是沒有體現在文檔中

例子

User.updateOne({ nickName: '張三' }, { overwrite: true });
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章