Node.js错误架构阵列路径的值无效

时间:2017-11-01 14:14:42

标签: node.js mongoose

我无法弄清楚这段代码有什么问题:

act.js

import mongoose from 'mongoose';
var Schema   = mongoose.Schema;

var ActSchema = mongoose.Schema(
  {
    name: { type: String },
    runs: [{ type: Schema.Types.ObjectId, ref: 'Run' }],
  }
)

export default mongoose.model('Act', ActSchema);

scheduleRun.js

import mongoose from 'mongoose';
import Act from './act'

var ScheduleRunSchema = mongoose.Schema(
  {
    act: [Act.ActSchema]
  }
)

export default mongoose.model('ScheduleRun', ScheduleRunSchema);

它出现以下错误:

  

TypeError:架构阵列路径act

的值无效

1 个答案:

答案 0 :(得分:1)

您正在导出Mongoose模型,但尝试使用该模式。

如果模型已经注册,那么您可以获得如下模式:

ext.kotlin_version = '1.2.0-beta-88'

或者,您可以尝试从 act.js 中将模式导出为命名导出:

var ActSchema = mongoose.model('Act').schema

...然后将架构导入 scheduleRun.js

...

export var ActSchema = mongoose.Schema(
  {
    name: { type: String },
    runs: [{ type: Schema.Types.ObjectId, ref: 'Run' }],
  }
)

...