该错误发生两次,第一次解决之后第二次碰到又没有想起来怎么解决.node
由于采用mongoose+node的后端项目.有两个表实现多对多关系,再中间表不作关联,只在两个主表作了后端
testlist: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Aginglist' }]
该字段是一个数组,查询到该记录后数组
const agingtest = await ctx.model.Agingtest.findById(agingid);
agingtest.testloglist.push(aginglog._id);
await agingtest.save();//报错代码
该代码再保存的时候,就会出现pushall 错误,这个问题主要是版本问题mongoose
只须要在创建schema的时候添加字段
usePushEach: true
1 const AgingtestSchema = new Schema( 2 { 3 testname: { type: String }, 4 createat: { type: Date, default: new Date() }, //建立时间 5 createuser: { type: String }, //建立人 6 agingdate: { type: Date, default: new Date().setHours(0, 0, 0, 0) }, //默认当前日期 7 testuser: { type: String }, //管理端登录ID 8 desc: { type: String }, 9 10 testloglist: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Aginglist' }] 11 }, 12 { 13 usePushEach: true 14 } 15 );