未按照架构插入数据

时间:2018-08-31 04:46:40

标签: mongodb mongoose mongoose-schema

我已经定义了mongoose模式,并尝试将数据插入mongodb中,但是没有按照定义的模式插入

export const EmpSchema: mongoose.Schema = new Schema({
  name: {
    type: String,
    required: true
  },
  empNo: {
    type: String,
    required: true
  },
  skill: {
    type: [String],
    required: true
  },
  address: {
    type: String,
    required: true
  }
}, {
  _id: false,
  versionKey: false,
  retainKeyOrder: true
});

它像数组元素一样存储为最后一个字段。

name
empno
address
skill

1 个答案:

答案 0 :(得分:0)

    export const EmpSchema: mongoose.Schema = new Schema({
      name: {
        type: String,
        required: true
      },
      empNo: {
        type: String,
        required: true
      },
      skill: {
        type: [String],
        required: true
      },
      address: {
        type: String,
        required: true
      }
    }, {
      _id: false,
      versionKey: false,
      retainKeyOrder: true
    });

YOUR SCHEMA DEFINATION IS CORRECT PLEASE CHECK THE CONTROLLER PART WHERE YOU PUT THE INSERT QUERY . THERE MATTERS A INSERTION ORDER