/** History requirement - Document can have embedded sub-documents - Document can have referenced documents - Document can be referenced by documents - On save: * copy current version * */ const mongoose = require('mongoose') const historySchema = new mongoose.Schema({ author: [mongoose.Schema.Types.ObjectId], created: Date, version: Number, tag: String, reference: [mongoose.Schema.Types.ObjectId] }) const basicSchema = { name: { type: String, maxlength: 20, required: true }, tag: { type: String, maxlength: 10, required: true }, description: { type: String, maxlength: 200 } } const collection = { ...basicSchema, __history: [historySchema] } module.exports = { basicSchema, collection }