alt alt:Gelincik doldurmak benim MongoDB</p> <p>Öğeler bu kurulum var belge
title: String
comments: [] // of objectId's
Yorumlar:
itemSchema = mongoose.Schema({
title: String,
comments: [{ type: Schema.Types.ObjectId, ref: 'comments' }],
});
Item = mongoose.model('items', itemSchema);
commentSchema = mongoose.Schema({
comment: String,
user: { type: Schema.Types.ObjectId, ref: 'users' },
});
Comment = mongoose.model('comments', commentSchema);
:
user: ObjectId()
item: ObjectId()
comment: String
İşte benim Gelincik şema var Eşyalarımı aldığım yer burası yorumlarla:
Item.find({}).populate('comments').exec(function(err, data){
if (err) return handleError(err);
res.json(data);
});
Yorumlar dizisini ilgili kullanıcıyla nasıl doldururum? Her yorumun bir kullanıcı ObjectId() olduğundan Sonuç nesneleri doldurmak çağıran bir tam örnek olarak
Bu sorunun kabul edilen yanıtında gösterildiği gibi iki aşamada yapabilirsiniz: http://stackoverflow.com/questions/19222520/populate-nested-array-in-mongoose – JohnnyHK