Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 当数据传递到Mongo模式时,数组元素丢失_Node.js_Arrays_Mongodb_Mongoose - Fatal编程技术网

Node.js 当数据传递到Mongo模式时,数组元素丢失

Node.js 当数据传递到Mongo模式时,数组元素丢失,node.js,arrays,mongodb,mongoose,Node.js,Arrays,Mongodb,Mongoose,我正在使用mongo和express构建一个测验应用程序 下面是我的模式的样子 const mongoose = require("mongoose") const Schema = mongoose.Schema const quizSchema = new Schema({ course: { type: String, required: true, }, title: { type: String, required:

我正在使用mongo和express构建一个测验应用程序

下面是我的模式的样子

const mongoose = require("mongoose")

const Schema = mongoose.Schema

const quizSchema = new Schema({
  course: {
    type: String,
    required: true,
  },
  title: {
    type: String,
    required: true,
  },

  options: [
    { type: String, required: true },
    { type: String, required: true },
    { type: String },
    { type: String },
    { type: String },
  ],
module.exports = Quiz = mongoose.model("Fifth_question", quizSchema)
例如,我有一个对象如下

{
  course: 'fruit',
  title: 'Laravel: Blade',
  option: [ 'orange', 'apple', 'grape', 'mango' ],
  answer: 'orange'
}
当我把这个对象传递给下面的schema liek

const quiz = new quiz(obj)
它释放数组元素,返回空数组

这些是我在网上找到的,但仍然不起作用。 同样的结果

options: {
  type: Array,
  default: []
}

or

options: [
  { option1: { type: String, required: true } },
  { option2: { type: String, required: true } },
  { option3: String },
  { option4: String },
  { option5: String },
],
有人能告诉我我错过了什么吗

还有最后一个,对象数组,如果我们不想用字符串数组和对象数组,我应该如何修复代码


事先非常感谢

可能只是一个打字错误。您的模式定义了
选项
(复数),但您的对象有
选项
(单数)可能只是一个输入错误。您的模式定义了
选项
(复数),但您的对象具有
选项
(单数)