MongoError: Cannot update '__v' and '__v' at the same time,错误解决办法
1.讲查询的结果,原封不动的插入到另一个表中,结果报错了:MongoError: Cannot update '__v' and '__v' at the same time,起初认为是mongodb副本集出现问题了,排查了mongodb,确定不是数据库问题了
看到这篇文章解决了https://stackoverflow.com/questions/33626456/mongoerror-exception-cannot-update-v-and-v-at-the-same-time
直接上解决的代码:
const userFind = await model.user.findById(userId)
const userInsert = userFind.toJSON();//查询出来的就是JSON,但是,删除__V的时候,插入bakuser表,还是报错MongoError: Cannot update '__v' and '__v' at the same time,最后,在userFInd后加了toJOSN方法,就完全解决了
delete userInsert.__v;
await model.bakuser.update({
_id: userId
}, {
$set: userInsert
}, {
upsert: true
});