Quantcast
Viewing latest article 2
Browse Latest Browse All 2

Mongoose model seperations

Im new to node and mongodb. I have the following mongoose model.

import { model, Schema } from 'mongoose';
import Joi from '@hapi/joi';

const profileSchema = new Schema({
  user: {
    type: Schema.Types.ObjectId,
    ref: 'users',
  },
  handle: {
    type: String,
    minlength: 2,
    maxlength: 20,
    required: true,
    trim: true,
  },
  company: {
    type: String,
    minlength: 1,
    maxlength: 100,
    trim: true,
  },
  website: {
    type: String,
    maxlength: 100,
    trim: true,
  },
  location: {
    type: String,
    maxlength: 100,
    trim: true,
  },
  status: {
    type: String,
    maxlength: 50,
    trim: true,
    required: true,
  },
  skills: {
    type: [String],
    required: true,
  },
  bio: {
    type: String,
    maxlength: 500,
    trim: true,
  },
  githubUserName: {
    type: String,
    maxlength: 50,
    trim: true,
  },
  experience: [
    {
      title: {
        type: String,
        maxlength: 100,
        trim: true,
        required: true,
      },
      company: {
        type: String,
        maxlength: 100,
        trim: true,
        required: true,
      },
      location: {
        type: String,
        maxlength: 100,
        trim: true,
        required: true,
      },
      from: {
        type: Date,
        required: true,
      },
      to: {
        type: Date,
      },
      current: {
        type: Boolean,
        default: false,
      },
      description: {
        type: String,
        maxlength: 500,
        trim: true,
      },
    },
  ],
  education: [
    {
      school: {
        type: String,
        maxlength: 100,
        trim: true,
        required: true,
      },
      degree: {
        type: String,
        maxlength: 100,
        trim: true,
        required: true,
      },
      fieldOfStudy: {
        type: String,
        maxlength: 100,
        trim: true,
        required: true,
      },
      from: {
        type: Date,
        required: true,
      },
      to: {
        type: Date,
      },
      current: {
        type: Boolean,
        default: false,
      },
      description: {
        type: String,
        maxlength: 500,
        trim: true,
      },
    },
  ],
  social: {
    youtube: {
      type: String,
      maxlength: 100,
      trim: true,
    },
    twitter: {
      type: String,
      maxlength: 100,
      trim: true,
    },
    facebook: {
      type: String,
      maxlength: 100,
      trim: true,
    },
    linkedin: {
      type: String,
      maxlength: 100,
      trim: true,
    },
    instagram: {
      type: String,
      maxlength: 100,
      trim: true,
    },
  },
  date: {
    type: Date,
    default: Date.now,
  },
});

export default model('profile', profileSchema);

I have created this model in a single file and it seems too big. So should I put experience, education and social into 3 seperate models? If so how should I do it? If I put these in to 3 seperate models, how can I link them with the profile model? An example would be highly appriciated.


Viewing latest article 2
Browse Latest Browse All 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>