将字段从一个MongoDB模式扩展到另一个MongoDB模式

将字段从一个MongoDB模式扩展到另一个MongoDB模式,mongodb,express,mongoose,mern,Mongodb,Express,Mongoose,Mern,我一直在构建一个MERN stack应用程序,根据注册期间选择的角色/状态,该应用程序将有3种不同的配置文件(比如新手、大师、战士)。 现在,每个配置文件只是新手配置文件的扩展,只需添加一个或两个字段,同时删除一个或两个字段 所以我根本不想复制和粘贴 有没有一种方法可以简单地将新手模式扩展到其他概要文件模式,并根据我的意愿进行修改 const mongoose = require('mongoose') const UserSchema = new mongoose.Schema({ nam

我一直在构建一个MERN stack应用程序,根据注册期间选择的角色/状态,该应用程序将有3种不同的配置文件(比如新手、大师、战士)。 现在,每个配置文件只是新手配置文件的扩展,只需添加一个或两个字段,同时删除一个或两个字段

所以我根本不想复制和粘贴 有没有一种方法可以简单地将新手模式扩展到其他概要文件模式,并根据我的意愿进行修改

const mongoose = require('mongoose')

const UserSchema = new mongoose.Schema({
 name : {
     type: String,
     required: true
 },
 // unique stops people from registering with same email
 email: {
     type: String,
     required: true,
     unique: true
 },
 password: { 
     type: String,
     required: true
  },
  avatar: {
      type: String,
  },
  role: {
 type: String,
 enum: ['novice', 'master', 'warrior'],
 required: true
 },
  date: {
      type: Date,
      default: Date.now
  }
})


module.exports = User = mongoose.model('user', UserSchema)

// novice.js

const mongoose = require('mongoose')

const NoviceSchema = new mongoose.Schema({
    // this links this schema to the user schema...
    // via object id
   user: {
       type: mongoose.Schema.Types.ObjectId,
       ref: 'user'
   },
   company: {
       type: String
   },
   website: {
       type:String
   },
   location: {
       type:String
   },
   status: {
       type:String,
    //    required:true
   },
   skills: {
       type:[String],
       required:true
   },
   bio: {
       type:String
   },
})

module.exports = Novice = mongoose.model('novice', NoviceSchema);