0

这是我的 AdminSchema,它在用户注册时输入用户名、密码和 AccountType。根据注册帐户类型,我们有两个选项,即(Judge,Student)wrt 创建我们需要将记录与相应的子集合连接起来

'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
  },

});

如何根据Admin Schema中accountType的选择来引用Judge Collection中的judgeID

var Judge = new Schema({
    judgeID : { type: ObjectId, ref: 'AdminSchema' },
    categorPriority_1 :{ type : String },
    categorPriority_2 :{ type : String },
    categorPriority_3 :{ type : String }


});

如何根据Admin Schema中accountType的选择来引用Judge Collection中的studentID

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);
4

0 回答 0