I'm using Mongo DB for my database and I'm using mongoose for managing it in my backend code.
I have 3 models in this details.
medias: {
type: [Schema.Types.ObjectId],
ref: "Media",
},
folders: {
type: [Schema.Types.ObjectId],
ref: 'Folder',
required: true,
},
so. we have medias in folder and we have folders in order.
the question is this. when I want to see an order details, I want to see my folders and it's medias.
I can use populate for accessing all folders of an order. but how can I access medias of any folder?
how can I make populate in populate?
const founded_item = await Order.findById(goal_id)
.populate({ path: 'folders', model: Folder, })
To populate nested references like medias inside folders when querying an Order, you need to use populate within populate in Mongoose.
const founded_item = await Order.findById(goal_id)
.populate({
path: 'folders',
model: 'Folder',
populate: {
path: 'medias',
model: 'Media'
}
});