0

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);
vikas madoori
  • 147
  • 1
  • 11
  • Already answered here https://stackoverflow.com/questions/19287142/populate-a-mongoose-model-with-a-field-that-isnt-an-id – Paradise228 Sep 25 '18 at 12:26
  • Thanks for help. But based on the input how should i decide in which collection it should insert like if person registers as Judge then it should insert in Judge Collection or if Student register it should insert it into Student Collection – vikas madoori Sep 25 '18 at 13:19
  • @Paradise228 check the above comment – vikas madoori Sep 25 '18 at 19:28

0 Answers0