Skip to content

Instantly share code, notes, and snippets.

@kof
Created March 30, 2011 22:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kof/895480 to your computer and use it in GitHub Desktop.
Save kof/895480 to your computer and use it in GitHub Desktop.
bootstrap file for mongoose models
var fs = require('fs'),
m = require('mongoose');
fs.readdirSync(__dirname).forEach(function(filename) {
var schamaName = filename.replace(/\.js$/, ''),
Schema = require('./' + schemaName);
m.model(schemaName, Schema);
});
@kof
Copy link
Author

kof commented Mar 30, 2011

Schema modules are in the same dir and file names should correspond model name.
// Website.js
var Website = new m.Schema({
title: String,
pages: [Page]
});

 module.exports = Website;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment