zoukankan      html  css  js  c++  java
  • mongoose pushall不支持的错误记录

    该错误发生两次,第一次解决以后第二次碰到又没有想起来怎么解决.

    因为采用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 错误,这个问题主要是版本问题

    只需要在建立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   );
    
    
  • 相关阅读:
    排序
    最小栈
    移除链表元素
    回文链表
    maven自动建立目录骨架
    maven的结构和构建命令
    递归
    链表的中间结点
    括号匹配
    软件工程个人作业01
  • 原文地址:https://www.cnblogs.com/beio/p/11037924.html
Copyright © 2011-2022 走看看