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 });