小编Dan*_*g93的帖子

Mongoose:由于值“[5ac5cfb41fca8a22f519cb22]”而无法转换为数组

我试图在现有游戏中插入一个回合,这给了我以下错误:

游戏验证失败:rounds.1.questions:Cast to Array 在路径“questions”处的值“[ 5ac5cfb41fca8a22f519cb22 ]”失败

架构的:

const roundSchema = Schema({
  roundNumber: {
    type: Number,
    required: true,
  },
  categories: {
    type: [String],
    required: true
  },
  questions: {
    type: [Schema.Types.ObjectID],
    ref: 'Question',
    required: true,
  }
});

const gameSchema = Schema({
  code: {
    type: String,
    required: true,
  },
  teams: {
    type: [Schema.Types.ObjectID],
    required: false,
  },
  rounds: [roundSchema]
});

const questionSchema = Schema({
  question: {
    type: String,
    required: true,
  },
  answer: {
    type: String,
    required: true,
  },
  category: {
    type: String,
    required: …
Run Code Online (Sandbox Code Playgroud)

casting mongoose node.js objectid

5
推荐指数
1
解决办法
2396
查看次数

标签 统计

casting ×1

mongoose ×1

node.js ×1

objectid ×1