how to refer to a schema in another folder

0

for example the following schemes are the following folders

cr/user
lms/content

this is the outline contained

user: {
        type: Schema.Types.ObjectId,
        ref: 'cr/user'
    }

How can I reference a user from the schema content?

because if I use it like this I get an error "Schema has not been registered for model"

    
asked by santiago 08.05.2018 в 07:34
source

1 answer

1

You are defining the reference incorrectly; this is not the model's route is the name that you give when exporting it using mongoose.model .

Example

If you have exported the user model as follows:

module.exports = mongoose.model('User', schema);

Then, the reference must be User :

user: {
    type: Schema.Types.ObjectId,
    ref: 'User',
}
    
answered by 08.05.2018 / 21:26
source