mongoose 全量更新

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012769002/article/details/80448167

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

猜你喜欢

转载自blog.csdn.net/u012769002/article/details/80448167