Socket
Socket
Sign inDemoInstall

mongoose-multitenant

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-multitenant - npm Package Compare versions

Comparing version 0.7.9 to 0.8.0

.travis.yml

27

Gruntfile.js
var f, semver;
var fs = require('fs');
semver = require('semver');

@@ -22,4 +22,7 @@

test: {
cmd:'NODE_ENV=test mocha'
cmd:function(ex) {
return f('NODE_ENV=test mocha %s', ex)
}
}
},

@@ -62,3 +65,21 @@ coffee: {

grunt.registerTask('test', ['dropTestDb', 'exec:test']);
grunt.registerTask('test', 'Run tests', function(test) {
var tasks = []
var files = fs.readdirSync('test');
var file;
if(test) {
tasks.push('exec:test:"test/' + test + '.js' + '"')
tasks.push('dropTestDb')
}
else {
for(var i=0;i<files.length;i++) {
file = files[i];
tasks.push('exec:test:"test/' + file + '"')
tasks.push('dropTestDb')
}
}
grunt.task.run(tasks);
});
};

27

index.js

@@ -8,3 +8,3 @@ /*

var dot, mongoose, owl, _;
var collectionDelimiter, dot, mongoose, owl, _;

@@ -21,2 +21,15 @@ mongoose = require('mongoose');

/*
Added by @watnotte
*/
collectionDelimiter = collectionDelimiter;
module.exports = function(delimiter) {
if (delimiter) {
return collectionDelimiter = delimiter;
}
};
mongoose.mtModel = function(name, schema) {

@@ -43,3 +56,3 @@ var extendPathWithTenantId, extendSchemaWithTenantId, modelName, multitenantSchemaPlugin, newSchema, origSchema, parts, pre, preModelName, precompile, split, tenantId, tenantModelName, uniq, _i, _len;

}
newPath.ref = tenantId + '__' + path.options.ref;
newPath.ref = tenantId + collectionDelimiter + path.options.ref;
precompile.push(tenantId + '.' + path.options.ref);

@@ -100,5 +113,5 @@ return newPath;

parts = name.split('.');
tenantId = parts[0];
modelName = parts[1];
tenantModelName = tenantId + '__' + modelName;
modelName = parts.pop();
tenantId = parts.join('.');
tenantModelName = tenantId + collectionDelimiter + modelName;
if (mongoose.models[tenantModelName] != null) {

@@ -119,3 +132,3 @@ return mongoose.models[tenantModelName];

split = pre.split('.');
preModelName = split[0] + '__' + split[1];
preModelName = split[0] + collectionDelimiter + split[1];
if ((mongoose.models[preModelName] == null) && mongoose.mtModel.goingToCompile.indexOf(preModelName) < 0) {

@@ -126,3 +139,3 @@ mongoose.mtModel(pre, null);

}
return this.model(tenantId + '__' + modelName, newSchema);
return this.model(tenantId + collectionDelimiter + modelName, newSchema);
} else {

@@ -129,0 +142,0 @@ return this.model(name, schema);

{
"name": "mongoose-multitenant",
"version": "0.7.9",
"version": "0.8.0",
"description": "Wrapper for Mongoose that allows for easy horizontal multitenancy (collection prefix per tenant)",

@@ -5,0 +5,0 @@ "main": "index.js",

Mongoose Multitenant
=====================
[![Build Status](https://travis-ci.org/jraede/mongoose-multitenant.png?branch=v0.8.0)](https://travis-ci.org/jraede/mongoose-multitenant)

@@ -15,2 +16,5 @@ This package facilitates horizontal multitenancy in one MongoDB database, obviously using Mongoose as the interaction layer.

## Usage

@@ -25,2 +29,9 @@ #### Pull in requirements

#### Changing collection delimiter
Thanks to @watnotte for this - if you want to change the delimiter from the default `__` you can do the following:
```javascript
require('mongoose-multitenant')('CUSTOM_DELIMITER');
```
#### Create a schema

@@ -27,0 +38,0 @@ With mongoose-multitenant you use all the same syntax for schema creation as you normally do with Mongoose, with the addition of the `$tenant` property on document references. This tells the system whether it is a reference to a document for the same tenant (`true`) or a root-level document without a tenant (`false`)

@@ -107,2 +107,17 @@ var barSchema, bazSchema, boofSchema, fooSchema, foobSchema, mongoose, multitenant, should, subSchema;

});
it('should be able to create a foo model for a tenant with a . in its name', function(done) {
var fooClass, myFoo,
_this = this;
fooClass = mongoose.mtModel('dottenant.org.Foo');
myFoo = new fooClass({
title: 'My Foo'
});
return myFoo.save(function(err, results) {
return mongoose.mtModel('dottenant.org.Foo').find(function(err, results) {
results.length.should.equal(1);
results[0].title.should.equal('My Foo');
return done();
});
});
});
it('should copy non-mongoose config options through to schema duplicates', function() {

@@ -109,0 +124,0 @@ mongoose.mtModel('tenant1.Bar').schema.paths.array.caster.options.$tenant.should.equal(true);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc