Mongoose Association query

// 
let articleSchema = new Schema({
    title: String,
    content: String
)}
// 
let commentSchema = new Schema({
    title: String,
    content: String,
    article: { type: Schema.Types.ObjectId, ref: "Article" }
)}
var Article = mongoose.model("Article", articleSchema );
var Comment = mongoose.model("Comment", commentSchema );

when I want to get the list of articles again, I use the article _ id to get the comments under the article. I have thought for a long time that "populate" can only retrieve the article from the comments. What should I do? it is impossible to write the ref of n comments in the article. It doesn"t feel realistic. Can you only get to the list of articles and go through each article again? Solve

Mar.02,2021

article can store a comment _ id array, so you can populate comments

.
let articleSchema = new Schema({
    title: String,
    content: String,
    comments:[{
    type: Schema.Types.ObjectId, ref: 'Comment'
    }]
)}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea6319-1dba.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea6319-1dba.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?