These are my data models:
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"
}
]
});
and :
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"
}
]
});
and here is my nodejs request which doesn't populate the comments into my template :
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});
}
});
}
});
});
which does't work! I want to populate comments from Feeds data model in to my template. i will be so grateful if someone could help, thank you.