getting schema attributes from Mongoose Model

Yes, it is possible.

Each schema has a paths property, that looks somewhat like this (this is an example of my code):

paths: {
    number: [Object],
    'name.first': [Object],
    'name.last': [Object],
    ssn: [Object],
    birthday: [Object],
    'job.company': [Object],
    'job.position': [Object],
    'address.city': [Object],
    'address.state': [Object],
    'address.country': [Object],
    'address.street': [Object],
    'address.number': [Object],
    'address.zip': [Object],
    email: [Object],
    phones: [Object],
    tags: [Object],
    createdBy: [Object],
    createdAt: [Object],
    updatedBy: [Object],
    updatedAt: [Object],
    meta: [Object],
    _id: [Object],
    __v: [Object]
}

You can access this through an model too. It’s under Model.schema.paths.

Leave a Comment