1
我使用Mongoose 4.1.12。我的模式:猫鼬:它没有找到引用它做了什么?
var UserSchema = new Schema({
_id: {type: String}, // unique nickname
name: {type: String}
});
var BookSchema = new Schema({
authors: [{type: String,ref:"User"}] // list of nicknames
});
让我们想象有2个用户注册,并昵称:伊戈尔和克里斯蒂娜。
还有与作者收集图书:伊戈尔,克里斯蒂娜,卢克。
然后我做的:
Book.findOne({}).populate("authors").exec(function(err,book){...})
现在一本书只包含2在“作家”集合对象,因为卢克用户不存在。
book: {
authors: [
{ _id: "igor", name: "Igor" },
{ _id: "kristina", name: "Kristina" }
]
}
我希望这样的事情:
book: {
authors: [
{ _id: "igor", name: "Igor" },
{ _id: "kristina", name: "Kristina" },
"luke"
]
}
这可能吗?
我编辑了我的帖子,使问题更清晰,请您再看看一下? – igorpavlov