The Mongoose Schema Registry allows developers to register schemas without creating a mongoose model. This allows extension of schemas later on prior to registering those models.
The following quick example should help you get started (taken from the ghiraldi framework mvc.js file):
File1js// First, declare the registry object.var registry =// The registry fires events when schemas are added.registry;// Add a schema to the registry using the add methodregistry;
You can modify an existing schema by calling the getSchema method. Since the registry is a singleton, requiring will give you the same object with the already registered schemas.
// File2.jsvar registry = ;var testSchema = registry;// From here, you can add things to your test schema.// When you're done, just re-add the schema. The new one will clobber// the old one.registry;
To finally register the schemas into mongoose models, just iterate through the schemas and call the mongoose.model method.
var keys = registry;_;