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
還沒有文檔化。。。
mongoose 源碼中
是存在這個參數可以覆蓋更新的,只是沒有體現在文檔中
例子
User.updateOne({ nickName: '張三' }, { overwrite: true });