Mongoose populate() returns array of objects instead of single object Mongoose populate() returns array of objects instead of single object mongoose mongoose

Mongoose populate() returns array of objects instead of single object


It makes sense since you in the schema definition have declared the category field to be an array:

category: [{ type: Schema.Types.ObjectId, ref: 'categories' }]

The following should work to not put it in an array (remove the []):

category: { type: Schema.Types.ObjectId, ref: 'categories' }

That is assuming that you indeed want only one category.