Skip to content

Instantly share code, notes, and snippets.

View jskod's full-sized avatar
🎯
Focusing

Tauqeer Awan jskod

🎯
Focusing
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 = {}) => {