Changing default users collection name for accounts package in Meteor

We ran into a peculiar issue while working with Meteor at Gummicube. We had two separate Meteor application that both needed to access the same MongoDB since they shared many of the same collections, but they needed to have their own users collections. This was a problem, since the users collection always had the default name of “users” and there was no official way to customize that collection name.

After digging around the source code, we came up with the following workaround. Put this in a .js file in your /lib folder in your Meteor project:

// let meteor uses 'custom_users' collection as 'users' collection
Accounts.users = new Mongo.Collection("custom_users", {
_preventAutopublish: true

Meteor.users = Accounts.users;

This makes sure both server and client side code will be using the updated users collection name. Hope this helps! And of course, if you have suggestions on a better way to do this – please share in the comments below.

This entry was posted in Development. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment