Node.js 如何在mongoose或mongodb中创建数据模型

Node.js 如何在mongoose或mongodb中创建数据模型,node.js,mongodb,mongoose,mongoose-schema,mongoose-models,Node.js,Mongodb,Mongoose,Mongoose Schema,Mongoose Models,比方说, 我有一些包含州(国家)、省和年份的数据,以及这些数据的条件,我将尝试用以下内容进行解释: state_a: { province: { name: 'prov_1', conditions: { year: 2019, condition: 'normal' }, conditions: { year: 2020, condit

比方说, 我有一些包含州(国家)、省和年份的数据,以及这些数据的条件,我将尝试用以下内容进行解释:

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,我希望代码能解释我的意思。我想在mongoose中创建模型。伙计们,你们能帮帮我吗?

你们需要这样做

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
              }
         }]

    }]

})