我们(从 MongoDB 3.4)升级到:
MongoDB:4.2.8
猫鼬:5.9.10
现在我们收到了这些错误。对于最小的例子,模型是:
[公司.js]
'use strict';
const Schema = require('mongoose').Schema;
module.exports = new Schema({
name: {type: String, required: true},
}, {timestamps: true});
and
[目标组.js]
'use strict';
const Schema = require('mongoose').Schema;
module.exports = new Schema({
title: {
type: String,
required: true,
index: true,
},
minAge: Number,
maxAge: Number,
companies: [Company],
}, {timestamps: true});
当我尝试更新目标组内的公司时
_updateTargetGroup(companyId, company) {
return this.targetGroup.update(
{'companies._id': companyId},
{$set: {'companies.$': company}},
{multi: true});
}
我收到
MongoError:更新路径“companies.$.updatedAt”会在“companies.$”处产生冲突
即使我前置
delete company.updatedAt;
delete company.createdAt;
我收到这个错误。
如果我尝试类似的数据库工具(Robo3T),一切正常:
db.getCollection('targetgroups').update(
{'companies.name': "Test 1"},
{$set: {'companies.$': {name: "Test 2"}}},
{multi: true});
当然我可以使用解决方法
_updateTargetGroup(companyId, company) {
return this.targetGroup.update(
{'companies._id': companyId},
{$set: {'companies.$.name': company.name}},
{multi: true});
}
(这确实有效),但我想了解这个问题,并且我们的项目中还有更大的模型也存在同样的问题。
这是一个问题吗{时间戳:true}?我寻找解释但找不到任何东西......:-(