Skip to content

Instantly share code, notes, and snippets.

View idodekerobo's full-sized avatar
👨‍💻
learning...👨🏾‍💻

Idode idodekerobo

👨‍💻
learning...👨🏾‍💻
View GitHub Profile
@jskod
jskod / multi-tenant.js
Created September 13, 2019 07:44
Multi-Tenant Mongoose Model Wrapper For NodeJS Based Applications
import mongoose, { Schema } from 'mongoose'
import { getCurrentTenantId } from './storage'
/**
Function will return another function, which will further return a mongoose discriminator.
The only difference here is that everytime you use the mongoose model, you will have to call a function,
but it will give you a freedom of passing tenant-based data.
*/
export function tenantModel(name, schema, options) {
return (props = {}) => {
@alancasagrande
alancasagrande / multitenant_server_multi_db.js
Last active May 7, 2021 12:04
Multi-tenant app example with multiple databases. It will create 40 databases, use this gist to the delete them afterwards: https://gist.github.com/alancasagrande/4aa8b4a45ff7c8829ff5
var express = require('express');
var mongoose = require('mongoose');
var dbs = {};
for (var i = 0; i < 40; i++) {
dbs['t' + i] = mongoose.createConnection('mongodb://localhost/t' + i + '__multitenant', { server: { poolSize: 5 } });
}
var app = express();