Skip to content

multiple connections and models with dots#11

Open
rosshinkley wants to merge 5 commits intojraede:masterfrom
rosshinkley:master
Open

multiple connections and models with dots#11
rosshinkley wants to merge 5 commits intojraede:masterfrom
rosshinkley:master

Conversation

@rosshinkley
Copy link

Not entirely sure this is the direction the base library should go in, but I thought I'd at least share changes I had to make during some recent projects.

multiple connections

The base library did not support non-default connections (eg, connections created using mongoose.createConnection). To correct that, the bulk of the functionality has been wrapped up in setup that takes the connection and delimiter, both optional.

This introduces breaking changes, as require(mongoose-multitenant)('delimiter') will no longer work. Instead, the usage would look more like:

var multitenant = require('mongoose-multitenant');
var mongoose = require('mongoose');
mongoose.connect('...');
multitenant.setup('CUSTOM_DELIMITER');

I've updated the readme where appropriate to reflect this change.

model names with dots

The @watnotte changes work great with tenants that have dots in their names. However, mongo (and consequently, mongoose) allows for dots in the collection and model names, respectively. This changeset changes the behavior such that collection/model names with dots are also okay, so long as you either 1) add the tenant explicitly using connection.mtModel.addTenant(tenantId) or 2) if the model is added to the tenant explicitly, eg var fooclass = mongoose.mtModel('tenant1.something', 'model.name'). The documentation has not been updated to reflect this, as I think it should Just Work (tm). However, I added tests to ensure both behaviors are supported, as well as the original default behavior of the last dot part being used as the model name.

gruntfile changes

As a consequence of being able to add multiple connections, the dropTestDb grunt task had to be modified to drop all of the test databases the multitenant tests now create.

I think that's everything. Feedback welcome.

@jraede
Copy link
Owner

jraede commented Nov 1, 2015

Looks great - I'll take a look over the next few days and probably make this the next major release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants