I have a Item
schema with an array of categories where I store some id
s :
const schema = new Schema<Item>(
...
categories:[
{
type: Schema.Types.ObjectId,
ref: 'Category',
autopopulate: { select:'name'}
}
]
...
)
Category:
const schema = new Schema<Category>({
slug: {
type: String,
required: true,
unique: true,
index: true,
},
name:{
type: String,
required:true,
}
});
and I am using the mongoose-autopopulate
package at the moment.
Is there a way to replace the ids
in the Item
schema with the appropriate name
when queried (with or without mongoose-autopopulate
) ?