1
子ユーザーをコメントし、それにしreffering、私はこの問題に捕まってしまった:はマングースは、単純なブログです、私は私の個人的なプロジェクトに取り組んでいます
私は3つのマングーススキーマがあります。
ブログ:
var blogSchema = new mongoose.Schema({
title: String,
image: String,
description: String,
body: String,
created: { type: Date, default: Date.now() },
comments: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Comment"
}
]
});
コメント:
var commentSchema = new mongoose.Schema({
text: String,
author_id: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
}
});
ユーザー:
var userSchema = new mongoose.Schema({
username: String,
password: String,
avatar_url: String,
email: String
});
そして、各ブログ記事にImが正常に動作しているが、その後、私はユーザ名を表示するには、Userモデルにアクセスする方法がわからない配列からのコメントを表示しようとするとavatar_urls
app.get("/blogs/:id",function(req,res){
Blog.findById(req.params.id).populate("comments").populate("author_id").exec(function(err,findBlog){
if(err){
res.redirect("back");
console.log(err);
}else{
res.render("show" , {blog: findBlog});
}
})
})
このようなことを意味しますか? 'ユーザ:{ タイプ:mongoose.Schema.Types.ObjectId、 ref:"ユーザ " } –
はい、ブログを作成しているユーザの場合 –
私はあなたの助けを借りて、ありがとう! –