Schema Examples — Mongoose/Node.js

Example record1

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

// Create Schema
const RecordSchema = new Record({
  name: {
    type: String,
    required: true
  },
  date: {
    type: Date,
    default: Date.now
  }
});

module.exports = Record = mongoose.model('record', RecordSchema);

To import schema

const Record = require('/path/Record');

  1. Adapted from https://github.com/bradtraversy/mern_shopping_list