Skip to content

Instantly share code, notes, and snippets.

@drenther
Last active March 13, 2019 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drenther/6d49b93f5522af453eb955052ffafb91 to your computer and use it in GitHub Desktop.
Save drenther/6d49b93f5522af453eb955052ffafb91 to your computer and use it in GitHub Desktop.
Export all the models
const mongoose = require('mongoose');
const personSchema = require('./models/person');
const dogSchema = require('./models/dog');
const catSchema = require('./models/cat');
const models = {
Person: mongoose.model('Person', personSchema),
Dog: mongoose.model('Dog', dogSchema),
Cat: mongoose.model('Cat', catSchema)
};
// explicitly create each collection
// for Mongoose multi-document write support which is needed for transactions
Object.values(models).forEach(model => {
model.createCollection();
});
module.exports = models;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment