How to populate the items array with full object?
This is what I try to do:
const documentCollection = await DocumentCollection.find({})
.populate({ path: 'items', populate: { path: 'documents', model: 'Document' } });
But items fields is empty in documentCollection. why? not sure what I missing here
Here is the mongoose model:
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' } }
)
);