let answer_Schema = mongoose.Schema({
userID: { type: String, require: true },
answer: { type: String, require: true },
comments: [comment_Schema],
profileID: { type: mongoose.Schema.Types.ObjectId, ref: "sign-ups" }
})
comment_Schema = {
profileID: { type: mongoose.Schema.Types.ObjectId, ref: "sign-ups" },
comment: { type: String },
subcomments: [comment_Schema],
dateTime: { type: String },
likes: [likes_Schema],
level: { type: Number }
}
this is the comment schema now this recursive model may go as deep as 5 levels, so it may look something like this:
{
answer: "SOME RANDOM ANSWER",
profileID:"5d8240ac0750a31f183d4016"
comments: [
{
_id: "5d93713d1c9d4400005230e5",
profileID :"614c7a75403a5636b4029f28",
comment : "klm",
subcomments : [
{
_id: "5d93713d1c9d4400005230r4",
profileID :"614c7a75403a5636b4029f28",
comment : "xyz",
subcomments : [
{
_id: "5d93713d1c9d4400005230456",
profileID :"614c7a75403a5636b4029f28",
comment : "wxy",
subcomments : [
{
_id: "5d93713d1c9d4400005230k7",
profileID :"614c7a75403a5636b4029f28",
comment : "abc",
subcomments : []
}
],
}
],
}
],
}
],
}
what i want here is to populate profileID from each comment even if it is deeply nested also including the profileID from answer itself
answers
.findOne()
.populate("questionID")
.populate("profileID")
.populate("comments.profileID")
.populate("comments.subcomments.profileID")
.populate("comments.subcomments.subcomments.profileID")
.populate("comments.subcomments.subcomments.subcomments.profileID")
.populate("comments.subcomments.subcomments.subcomments.subcomments.profileID")
this is what i have tried.
i have looked up at this process but i couldn't implement this to my requirements.
const userSchema = new Schema({
name: String,
friends: [{ type: ObjectId, ref: 'User' }]
});
can someone pls just guide me on this, thnks would appreciate it.