mongoose pushall不支持的錯誤記錄

該錯誤發生兩次,第一次解決之後第二次碰到又沒有想起來怎麼解決.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   );