我正在尝试在 Node 的模型中引用另一个对象,
User = new Schema({
username: {
type: String,
index: {unique: true}
}
});
Idea = new Schema({
Creator: {
type: User
}
});
但我收到此错误 “创建者”处未定义类型您尝试嵌套模式吗?您只能使用 refs 或数组进行嵌套。
我相信我想使用 refs,但找不到关于它的文档,有人可以帮助我。谢谢
最佳答案
我在这里找到了我自己问题的答案。
User = new Schema({
username: {
type: String,
index: {unique: true}
}
});
Idea = new Schema({
Creator: {
type: Schema.ObjectId,
ref: 'User'
}
});
关于node.js - Mongodb 类型引用 Node ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9338964/