mongoose-multitenancy

The best of both worlds Mongoose.discriminator & mongoose-multitenant

MIT License

Downloads
59
Stars
9
Committers
3

mongoose-multitenancy

The best of both worlds Mongoose.discriminator & mongoose-multitenant This package uses the mongoose discriminator functionality to extend schemas and uses the logic of mongoose-multitenant to create the models. Right now multitenancy just works with collections.

Installation

npm install mongoose-multitenancy

@NOTE: It requires mongoose as peerDependency.

Usage

var mongoose = require('mongoose');

// It automatically adds logic to mongoose.

var multitenancy = require('mongoose-multitenancy');

multitenancy.setup();

var LogSchema = new mongoose.Schema({
    entry: {
        type: String,
        required: true
    },
    user: {
        type: new mongoose.Schema({
            username: {
                type: String,
                required: true
            }
        })
    }
});

mongoose.mtModel('Log', LogSchema);

Tests

npm test