Package Exports
- multi-tenant
- multi-tenant/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (multi-tenant) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Multi tenant with mongoose
Installation
Before installing, download and install Node.js. Node.js 14 or higher is required.
Installation is done using the
npm installcommand:
Using npm:
# Install package with npm
$ npm install multi-tenantUsing yarn:
# Install package with yarn
$ yarn add multi-tenantImport module
ES5
const multiTenant = require('multi-tenant');
multiTenant.connectionDb();
#Or
const { connectionDb } = require('multi-tenant');
connectionDb();
ES6
import * as multiTenant from 'multi-tenant';
multiTenant.connectionDb();
#Or
import { connectionDb } from 'multi-tenant';
connectionDb();
Get Model
Inside the function that handles the logic where to connect to the database. Usually in controller, service files or anywhere you want to use.
Let's use getModelByTenant function to call Model.
import { getModelByTenant } from 'multi-tenant';
const User = await getModelByTenant({ name: 'ModelName' });
API Documentation
getModelByTenant function expose following api:
connectionDb(options)
The exported connectionDb function a data object one optional argument.
connectionDb(Object):
Default: { path }
pathargument is path to the directory where theModelis stored Value default of path is.- Default value of
pathargument ispath.resolve(process.cwd(), 'models'). This is the path to the Model folder located at the root of the project. - If you have a different directory map architecture, use this parameter as an option. You can completely customize this input parameter.
Authors and acknowledgment
- Project manager:
tungduy.dev@gmail.com
Support
Reach out to me at one of the following places!
- Email: tungduy.dev@gmail.com
- Phone: 0358001357
License
Copyright © 2020 FPT VPN. Crafted with ❤️ by Tùng Duy - tungduy.dev@gmail.com. Released under the MIT License.
This file was generated by Tùng Duy, v1.1.0, on Sept 23, 2021.