【问题标题】:mongoose add more key:value inside ref field猫鼬在 ref 字段中添加更多键:值
【发布时间】:2020-11-24 00:49:33
【问题描述】:
   organs: [
    {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Organ',
      healthValue: { // i want to add this field but it is becoming invalid, not generating auto with default val
        type: Number,
        default: 0,
      }
    },
  ],

我有一个用户架构,并且此架构中还有 organs 键。我用参考方式保存器官以获取属于用户器官。我也应该保持器官健康值,但我不能像上面一样将它放在参考字段中。我怎样才能做到这一点?我不能添加更多键:值来填充(类型和引用)字段吗?

【问题讨论】:

    标签: javascript mongodb mongoose populate


    【解决方案1】:
       organs: [
        {
          organId: {
            type: mongoose.Schema.Types.ObjectId,
            ref: 'Organ',
          },
          healthValue: {
            type: Number,
            default: 0,
          },
          isOwned: {
            type: Boolean,
            default: false,
          },
        },
      ],
    

    我想我用上面的代码块解决了,我确实使用了错误的语法

    【讨论】:

      猜你喜欢
      • 2018-08-26
      • 2014-01-12
      • 2018-05-03
      • 2018-11-28
      • 2018-12-03
      • 1970-01-01
      • 2017-03-15
      • 2020-09-13
      • 2020-02-17
      相关资源
      最近更新 更多