我正试图在我的模式之间做一些关系,我的解决方案有些问题.这是我的设备架构:
var deviceSchema = schema({
name : String,
type : String,
room: {type: mongoose.Types.ObjectId, ref: 'Room'},
users: [{type:mongoose.Types.ObjectId, ref: 'User'}]
});
Run Code Online (Sandbox Code Playgroud)
这里的房间架构:
var roomSchema = schema({
name : String,
image : String,
devices: [{type: mongoose.Types.ObjectId, ref: 'Device'}]
});
Run Code Online (Sandbox Code Playgroud)
猫鼬抛出错误
类型错误:未定义的类型
ObjectID,在room你尝试筑巢的架构?您只能使用refs或数组进行嵌套.
如果我改变room: {type: mongoose.Types.ObjectId, ref: 'Room'},对room: {type: Number, ref: 'Room'},一切正常.你能解释一下为什么会这样吗?