encountered a problem when trying to tamper with a forum with express+mongoose to implement the comment function.
model: of the post
const ArticleSchema = new Schema({
author: { type: Schema.Types.ObjectId, ref: "User" },
createTime: { type: Date },
thumb: [{ type: Schema.Types.ObjectId, ref: "User" }],
comment: [{ type: Schema.Types.ObjectId, ref: "Comment" }],
text: String
});
model: of comments
const CommentSchema = new Schema({
text: String,
createTime: { type: Date },
poster: { type: Schema.Types.ObjectId, ref: "User" },
posts: {type: Schema.Types.ObjectId, ref: "Article"}
})
render data:
Article.find()
.sort("-createTime")
.populate("author")
.populate("comment")
.exec((err, articles) => {
if (err) return next(err)
res.render("container/index", {
title: "xxxx",
articles
})
})
Front end:
:comments[i].text
: comments[i].poster
can get the content of the comment, but the reviewer displays the value of _ id, in which case should I query User again?