DEV Community

Discussion on: designing database

Collapse
 
brandinchiu profile image
Brandin Chiu

How a database is designed is determined heavily by the engine used.

In this case, a noSQL database through MongoDB requires less structure to use. That's one of the inherent benefits of a noSQL model.

You're actively choosing to reduce the overhead of your data store. This means your data integrity must be managed by your application instead.

In that case, it really doesn't matter that much what your overall schema looks like, so long as its comfortable to use, and isn't excessively horizontal in scale (many different records vs alot of data in single records).

What you have above is totally reasonable, but understand that it would look very different in a relational model.

I would however suggest changing role to roles as an array of role objects.

You can then be safe knowing that your data will handle multiple roles form the start.

Collapse
 
anshulnegitc profile image
Anshul Negi

This is how I have designed Model

const userSchema = mongoose.Schema({
email: { type: String, require: true },
address: { type: String, require: true },
role:{ type: String, require: true },
password:{ type: String, require: true },
extraInformation: {
firstname: { type: String, minlength: 1, maxlength: 255, require: true },
lastname: { type: String, minlength: 1, maxlength: 255, require: true },
sales : {
attachments: { type: String, minlength: 1, maxlength: 255, require: true },
experience: { type: String, require: true, minlength: 1, maxlength: 255 },
education: { type: String, require: true, minlength: 1, maxlength: 255 },
}
},
marketting: {
teamName: { type: String, minlength: 1, maxlength: 255 },
members: { type: String, minlength: 1, maxlength: 255, require: true },
attachments: { type: String, minlength: 1, maxlength: 255 },
}
});