【问题标题】:how to change a value of specific object in an array of objects in mongoose schema?如何更改猫鼬模式中对象数组中特定对象的值?
【发布时间】:2020-05-12 22:56:47
【问题描述】:

我有一个包含数组类型对象的架构,我想制作一个 api 来更改该数组中的特定字段,可能会更改其名称或删除它

const customerSchema = mongoose.Schema({
    _id: mongoose.Schema.Types.ObjectId,
    name: {
        type: String,
        require: true
    },
    description: String,
    fields: {
       type: [{
        name: String,
        environment: String,
        challenges: String,
        solution: String
    }],
    default: []
}
});

如何对字段数组的对象进行补丁或删除请求

【问题讨论】:

    标签: javascript arrays node.js json patch


    【解决方案1】:

    我发现如果有人遇到这个问题,我可以使用嵌套文档

    【讨论】:

      猜你喜欢
      • 2019-10-30
      • 2022-10-07
      • 1970-01-01
      • 2019-03-21
      • 2019-08-21
      • 2021-12-28
      • 2016-09-02
      • 2021-05-14
      • 2021-07-03
      相关资源
      最近更新 更多