Mongodb类型参考节点 [英] Mongodb type reference node
本文介绍了Mongodb类型参考节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试引用节点模型中的另一个对象,
I am trying reference another object in a model in node,
User = new Schema({
username: {
type: String,
index: {unique: true}
}
});
Idea = new Schema({
Creator: {
type: User
}
});
但出现此错误Undefined type at "creator" Did you try nesting Schemas? You can only nest using refs or arrays.
,我相信我想使用refs,但找不到有关它的文档,有人可以帮助我.谢谢
but I get this error Undefined type at "creator" Did you try nesting Schemas? You can only nest using refs or arrays.
I believe I want to use refs, but could not find documentation on it, can some one help me out. Thanks
推荐答案
我在这里找到了自己的问题的答案.
I found out the answer to my own question here it is.
User = new Schema({
username: {
type: String,
index: {unique: true}
}
});
Idea = new Schema({
Creator: {
type: Schema.ObjectId,
ref: 'User'
}
});
这篇关于Mongodb类型参考节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文