I have two schemas: Category, and User
Category schema is defined as follows:
title: {
type: String,
required: [true, 'Title field is required'],
unique: true
},
type: {
type: String,
required: [true, 'Type field is required'],
}
User schema
email: {
type: String,
required: true
},
isActive: {
type: Boolean,
default: true,
select: false,
},
categories: [{ /* Category schema object */}],
What I'm trying to implement is when ever a user registers, the categories array must be required, and each object within it must match and follow the predefined category schema and have an objectID.
How to do that with Mongoose?
categories: [Category]. Please refer to mongoose documentation