Javascript 如何访问引用的模式';带有Nodejs和mongoose的特定数据
我想在我的网站上发表评论。我只想获取我通过id找到的帖子的评论,并访问这些评论的数据 这是我的路线Javascript 如何访问引用的模式';带有Nodejs和mongoose的特定数据,javascript,node.js,mongodb,mongoose,mongoose-schema,Javascript,Node.js,Mongodb,Mongoose,Mongoose Schema,我想在我的网站上发表评论。我只想获取我通过id找到的帖子的评论,并访问这些评论的数据 这是我的路线 Campground.findById(req.params.id).populate("comments").exec(function(err, foundCampground){ if(err){ console.log(err); }else{ User.findById(req.user._id, (err,
Campground.findById(req.params.id).populate("comments").exec(function(err, foundCampground){
if(err){
console.log(err);
}else{
User.findById(req.user._id, (err, user)=>{
if(err){
console.log(err);
}else{
Campground.findById({'foundCampground.comments._id': Comments._id}, (err, comments)=>{
console.log("Comments of this post "+comments);
Comments.find({"author.id": user.id}, function(err, comment){
var authID = foundCampground.author.id;
var userID = user.id;
var commentIDs = [];
comment.forEach(function(yorum){
commentIDs.push(yorum.author.id);
});
var commentID = commentIDs[0];
console.log("alinan comments"+comment);
console.log("Comment Id " + commentID);
console.log("UserID "+userID);
if(userID == commentID){
console.log("EQUALO MORUQA");
}
res.render("campgrounds/show",{campground: foundCampground, authID: authID, userID: userID, commentID: commentID});
});
});
}
});
}
});
这是我的露营地模型
var campgroundSchema = new mongoose.Schema({
name: String,
image: String,
description: String,
comments: [{
type: mongoose.Schema.Types.ObjectId,
ref: "Comment"
}],
author: {
id: String,
user: String,
}
});
这是我的评论模型
var commentSchema = new mongoose.Schema({
text: String,
author:{
username: String,
id: String,
}
});
我应该写什么作为查询来只获取FoundCampGrand的评论