Best way to model User Schema with varying roles?

Let’s say I have a user document:

{
    firstName: John,
    lastName: Doe,
    email: john.doe@email.com,
    password: @#@#^#&^*,
    roles: ['client', 'agent', 'owner'],
}

What is the best way to allow certain properties only on a specific role (one account can have multiple roles)? For example, client can leave a review but owner can’t. If a user only has an owner role, I don’t want the review property in the user document.

1 Like

Hi there Darnell, I’ve been asking the same question for some time and what I found out is, first to create a base user model with the properties that all the user roles share and then use mongoose discriminator to extend on that base model. I don’t really know if it is the best practice or not, if someone from the MongoDB team answers your question or you found some different approach that worked for you it would be great if you share it with me too.