Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 2 months ago
JSON representation

The best of both worlds Mongoose.discriminator & mongoose-multitenant

Awesome Lists containing this project

README

        

## mongoose-multitenancy

[![Build Status](https://travis-ci.org/jorgecuesta/mongoose-multitenancy.svg?branch=master)](https://travis-ci.org/jorgecuesta/mongoose-multitenancy)
[![Coverage Status](https://coveralls.io/repos/github/jorgecuesta/mongoose-multitenancy/badge.svg?branch=master)](https://coveralls.io/github/jorgecuesta/mongoose-multitenancy?branch=master)
[![npm version](https://badge.fury.io/js/mongoose-multitenancy.svg)](https://badge.fury.io/js/mongoose-multitenancy)
[![Dependency Status](https://david-dm.org/jorgecuesta/mongoose-multitenancy.svg)](https://david-dm.org/jorgecuesta/mongoose-multitenancy)
[![peerDependency Status](https://david-dm.org/jorgecuesta/mongoose-multitenancy/peer-status.svg)](https://david-dm.org/jorgecuesta/mongoose-multitenancy#info=peerDependencies)
[![devDependency Status](https://david-dm.org/jorgecuesta/mongoose-multitenancy/dev-status.svg)](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