Inheritance in mongoose

Hello I need to inherit my schemas in mongoose library. Are there complete plugins for that? Or how should I do that myself?

I need to inherit all pre, post, init middleware from a Base schema also.

For others looking for this functionality, Mongoose 3.8 now has Schema Inheritance via Discriminator functionality:

https://github.com/LearnBoost/mongoose/pull/1647

You may want to look at using a Mongoose Plugin:

A plugin that does what you want 'out of the box' is here:

Check the models of this framework for Mongoose:

https://github.com/codexar/rode#models-with-mongoose

This is an example of who to extend shemas with this framework:

First of all define your schema inside a new "rode model":

var rode = require('rode');

var User = rode.Model.extend({
  name: 'User',
  schema: {
    name: {
      type: 'String',
      unique: true
    },
    email: String,
    password: String
  }
});

Now you should call extend method:

var Admin = User.extend({
  name: 'Admin',
  // The schema for admins is the schema for users + their own schema
  schema: {
    lastAccess: Date
  }
});

But have in mint this note extracted from the framework github: "Both models will share the same collection on MongoDB. Documents of the extended models will have an attribute _type to differentiate."