Here is my AdminSchema which takes input of Username, Password and AccountType while registration of user. Based on the registration accounttype we have two options i.e., (Judge,Student) w.r.t creation we need to connect the record with the respective sub collection
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var AdminSchema = new Schema({
username: {
type: String,
required: 'Kindly enter the name of the task'
},
password:{
type:String
},
accountType : {
type : String
},
Created_date: {
type: Date,
default: Date.now
},
});
How to reference the judgeID in Judge Collection based on the selection of accountType in Admin Schema
var Judge = new Schema({
judgeID : { type: ObjectId, ref: 'AdminSchema' },
categorPriority_1 :{ type : String },
categorPriority_2 :{ type : String },
categorPriority_3 :{ type : String }
});
How to reference the studentID in Judge Collection based on the selection of accountType in Admin Schema
var Student = new Schema({
studentID : { type: ObjectId, ref: 'AdminSchema' },
projectName : { type : String },
memberName_1 : { type : String },
memberName_2 : { type : String },
memberName_3 : { type : String },
});
module.exports = mongoose.model('Admin', AdminSchema);
module.exports = mongoose.model('Judge', Judge);
module.exports = mongoose.model('Student', Student);