【发布时间】:2018-06-23 17:05:01
【问题描述】:
这些是我的数据模型:
var campSchema = new mongoose.Schema({
image : String,
description : String,
comment: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Comment"
}
],
feeds : [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Feed"
}
]
});
和:
var feedSchema = new mongoose.Schema({
text : String,
createdAt: { type: Date, default: Date.now },
author : {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
username: String
},
comment: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Comment"
}
]
});
这是我的 nodejs 请求,它没有将 cmets 填充到我的模板中:
app.get("/feeds", isLoggedIn, function(req, res) {
console.log(req.user);
Camp.find({}).populate("feeds").populate("feeds.comment").exec(function(err, myCamp){
if(err){
console.log(err);
} else {
myCamp.forEach(function(camp){
if(camp.address === req.user.address){
console.log(building);
res.render("feeds/feeds", {building : building});
}
});
}
});
});
这是行不通的!我想将 Feeds 数据模型中的 cmets 填充到我的模板中。 如果有人可以提供帮助,我将不胜感激,谢谢。
【问题讨论】:
-
您好,请查看链接 1) stackoverflow.com/questions/28179720/…。 2)stackoverflow.com/questions/19222520/…。 Mongoose 4.5 及更高版本支持...