Skip to content

Sample of tenant application using MongoDB Descriminator keys to separate documents

Notifications You must be signed in to change notification settings

dataclear/node-tenant-sample

Repository files navigation

node-tenant-sample

Sample of tenant application using MongoDB Descriminator keys to separate documents

Combines the following

Standard models can be declared as below

const mongoose = require('mongoose');
const multiTenant = require('./tenancy/multiTenant');
// ...
const tenantSchema = new Schema({
 // fields
});

module.exports = multiTenant.tenantlessModel('tenant', tenantSchema);

Models that need to be split by tenant are defined using the tenantModel helper

const mongoose = require('mongoose');
const multiTenant = require('./tenancy/multiTenant');

mongoose.Promise = global.Promise;
const Schema = mongoose.Schema;

const orgSchema = new Schema({
 // fields
});

module.exports = multiTenant.tenantModel('org', orgSchema);

When using the models it's vital to declare them using their function:

// instead of
let foundOrg = await orgModel.findById(id);

// You would use
let foundOrg = await orgModel().findById(id);

About

Sample of tenant application using MongoDB Descriminator keys to separate documents

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published