https://github.com/jorgecuesta/mongoose-multitenancy
The best of both worlds Mongoose.discriminator & mongoose-multitenant
https://github.com/jorgecuesta/mongoose-multitenancy
mongoose mongoose-multitenancy mongoose-plugin
Last synced: about 1 year ago
JSON representation
The best of both worlds Mongoose.discriminator & mongoose-multitenant
- Host: GitHub
- URL: https://github.com/jorgecuesta/mongoose-multitenancy
- Owner: jorgecuesta
- License: mit
- Created: 2016-06-06T21:01:04.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-01-11T12:49:27.000Z (over 3 years ago)
- Last Synced: 2025-06-30T03:03:00.530Z (about 1 year ago)
- Topics: mongoose, mongoose-multitenancy, mongoose-plugin
- Language: JavaScript
- Homepage:
- Size: 143 KB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## mongoose-multitenancy
[](https://travis-ci.org/jorgecuesta/mongoose-multitenancy)
[](https://coveralls.io/github/jorgecuesta/mongoose-multitenancy?branch=master)
[](https://badge.fury.io/js/mongoose-multitenancy)
[](https://david-dm.org/jorgecuesta/mongoose-multitenancy)
[](https://david-dm.org/jorgecuesta/mongoose-multitenancy#info=peerDependencies)
[](https://david-dm.org/jorgecuesta/mongoose-multitenancy#info=devDependencies)
The best of both worlds [Mongoose.discriminator](http://mongoosejs.com/docs/discriminators.html) & [mongoose-multitenant](https://github.com/rosshinkley/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.
### Installation
`npm install mongoose-multitenancy`
> @NOTE: It requires mongoose as peerDependency.
### Usage
```javascript
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