arashsheyda / nuxt-mongoose

A Nuxt module for simplifying the use of Mongoose in your project.
https://docs.arashsheyda.me/nuxt-mongoose
69 stars 11 forks source link

Type error encountered while inserting data #28

Closed Ena-Heleneto closed 8 months ago

Ena-Heleneto commented 8 months ago

First I have a model like this

const templateSchema = {
  templateId: [{ type: String, required: [true, '未插入模板id'], index: true }],
  name: [{ type: String, required: [true, '未插入类型名称'], index: true }],
  version: [{ type: String, required: [true, '未插入版本号'], index: false }],
  status: [{ type: Number, required: [true, '未插入启用状态'], index: false }],
  process: [{ type: {}, required: [true, '未插入流程'], index: false }],
  createDate: [{ type: Date, required: [true, '未插入创建时间'], index: false }],
  updateDate: [{ type: Date, required: [false, '未插入创建时间'], index: false }],
  founderId: [{ type: Number, required: [true, '未插入创建人id'], index: false }],
  deleteFlag: [{ type: Number, required: [true, '未插入删除标志'], index: false }],
}

const SystemTemplates = defineMongooseModel('HW_Templates', templateSchema, { collection: 'HW_Templates' })

Next, I'll perform the insert

SystemTemplates.create({
      templateId: `temp${new Date().getTime()}`,
      createDate: new Date(),
      updateDate: new Date(),
      founderId: 1,
      status: 1,
      deleteFlag: 0,
})

But I got this image

The data is converted to array type

I don't know what happened, is it a new feature?

devDependencies Version{ "nuxt-mongoose": "^1.0.2" }

arashsheyda commented 8 months ago

You just need to remove the [ ] from schema props, example: name: { type: String, required: [true, 'custom error'], index: true },

Ena-Heleneto commented 8 months ago

ooh, I understand, thank you