【问题标题】:How to make a model of data in mongoose or mongodb如何在 mongoose 或 mongodb 中制作数据模型
【发布时间】:2021-07-08 17:54:14
【问题描述】:

让我们说, 我有一些包含州(国家)、省和年份的数据,以及条件,我将尝试在下面解释:

state_a: {
    province: {
        name: 'prov_1',
        conditions: {
           year: 2019,
           condition: 'normal'
        },
        conditions: {
           year: 2020,
           condition: 'not normal'
        }
    },
    province: {
        name: 'prov_b',
        conditions: {
           year: 2019,
           condition: 'not normal'
        },
        conditions: {
           year: 2020,
           condition: 'not normal'
        }
    }
},
state_b: ......... etc

实际上,我不知道如何解释它:D,我希望代码可以解释我的意思。我想在猫鼬中创建模型。伙计们,你们能帮帮我吗?

【问题讨论】:

    标签: node.js mongodb mongoose mongoose-schema mongoose-models


    【解决方案1】:

    你需要做这样的事情。

    const dataSchema =  new mongoose.Schema({
    State: {
            type: String,
            required: true
           },
    Province: [{
            name: {
                type: String;
                required: true
               }
            conditions: [
            { 
               year: { 
                  type: Number,
                  required: true
                  },
    
               condition: {
                  type: String,
                  required: true
                  }
             }]
    
        }]
    
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-21
      • 2021-06-18
      • 2018-11-05
      • 2019-03-15
      • 1970-01-01
      • 1970-01-01
      • 2018-07-10
      • 1970-01-01
      相关资源
      最近更新 更多