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.
npm install mongoose-multitenancy
@NOTE: It requires mongoose as peerDependency.
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