【发布时间】:2015-04-21 11:19:38
【问题描述】:
我正在尝试在我的模式之间建立一些关系,但我的解决方案存在一些问题。 这是我的设备架构:
var deviceSchema = schema({
name : String,
type : String,
room: {type: mongoose.Types.ObjectId, ref: 'Room'},
users: [{type:mongoose.Types.ObjectId, ref: 'User'}]
});
这里是房间架构:
var roomSchema = schema({
name : String,
image : String,
devices: [{type: mongoose.Types.ObjectId, ref: 'Device'}]
});
Mongoose 抛出错误
TypeError: Undefined type
ObjectIDatroom你尝试过嵌套吗 模式?您只能使用 refs 或数组进行嵌套。
如果我将 room: {type: mongoose.Types.ObjectId, ref: 'Room'}, 更改为 room: {type: Number, ref: 'Room'}, 一切正常。你能解释一下为什么会这样吗?
【问题讨论】:
标签: javascript node.js mongodb mongoose