Ich mache eine Blogapp. Zwei Modell Kommentar und Userprofile, sieht Kommentar etwas wie folgt aus:mongoose wie man ein Array referenziert innerhalb des Modells
var commentSchema = new Schema({
userId: {type: Schema.Types.ObjectId, ref: 'userProfile'},
replyCommentId: [{type: Schema.Types.ObjectId, ref:'Comment'}],
commentDesc: String,
date: {type: String, default: Date.now()}
});
Ich habe gespeichert Antworten als Kommentare selbst und Haupt Kommentar über replycomment id in Array gespeichert verwiesen.
Ich habe versucht, diese Antwortfelder zu füllen.
commentsModel.findOne({_id: commentId}).populate('replyCommentId')
.populate('replyCommentId.userProfile').exec(function (err, docs) {
cb(err, docs);
})
I replyCommentId
mit Modell aber userProfile
innerhalb replycommentId
füllen könnte, ist nicht aufgefüllt zu werden.
Es funktionierte für mich. Ich habe deine Logik. Vielen Dank. Ich könnte Ihnen einen positiven Kommentar geben, aber ich bin neu, wenn ich überlaufe und ich baue meinen Ruf auf. –
Nun, wenn Sie meine Antwort akzeptieren Sie erhalten 2 Ruf;) –