Как заполнить массив элементов полным объектом?
Вот что я пытаюсь сделать:
const documentCollection = await DocumentCollection.find({})
.populate({ path: 'items', populate: { path: 'documents', model: 'Document' } });
Но items
поля пусты в documentCollection
. Зачем? не уверен, что мне здесь не хватает
Вот модель мангуста:
export const DocumentsCollection = mongoose.model('Document-Collection',
new mongoose.Schema({
name: { type: String },
items: [
{
name: { type: String },
documents: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Document' }],
},
],
})
);
export const Document = mongoose.model( 'Document',
new mongoose.Schema(
{
name: { type: String },
description: { type: String }
},
{ timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' } }
)
);
Я думаю, что вы пропустили 's' в documents
.
const documentCollection = await DocumentCollection.find({})
.populate({ path: 'items', populate: { path: 'documents', model: 'Document' } });
все же случилось.
Попробуй это:
const documentCollection = await DocumentCollection.find({})
.populate('items.documents');
Я отредактировал свой ответ, я думаю, вы пропустили s в
path: 'documents'