I am learning Mongodb and I am using Mongoose and I would like to create a very dynamic registration process. I managed to complete the first step of registration using Passport, and everything works fine, I created a user and he is present in the database. Now my registration process will continue, and the user will have to choose a "role": which user are you? There are two options: basic and advanced. Basic has only 3 properties, and advanced has 3 basic properties, plus several others.
I need to expand userSchema or add new fields based on this role, but after a week it still does not work, and I tried a lot of NPM like: mongoose-relationship or mongoose-extension-scheme .
This is basically what I have:
userSchema = new Schema({ id : Number, email : { type: String, required: true }, role : { type: String, required: true }, profile : { ... } // Profile fields are different for each role. }); // profile 1 basicSchema = new Schema({ info1 : { type: String, required: true }, info2 : { type: String, required: true }, info3 : { type: String, required: true } }); // profile 2 advancedSchema = new Schema({ info1 : { type: String, required: true }, info2 : { type: String, required: true }, info3 : { type: String, required: true }, info4 : { type: String, required: true }, info5 : { type: String, required: true }, info6 : { type: String, required: true } });
The user already exists, and he is on the screen where he needs to select a role and fill out the selected profile.
For information, I use nodejs and expressjs .
I hope you can help. Thanks.