Reputation: 1891
We have more than one website which points to same MongoDB. For example front facing public website, internal admin website, etc.
We would like to have different users collection for different website. Is there any way to instruct Meteor to user different collection name in actual DB while accessing users collection using Meteor.users variable.
Upvotes: 3
Views: 693
Reputation: 1652
This is not tested, but from the first look, this could be a feasible way to change the name of user collection. Place this code somewhere in /lib folder:
Accounts.users = new Mongo.Collection("another_users_collection", {
_preventAutopublish: true,
});
Meteor.users = Accounts.users;
Upvotes: 1
Reputation: 837
No, sadly this is hardcoded into the package and as Brian said, the package offers no room for customization.
However, you could very easily add a new key accountType
for each document in the Meteor.users
collection. accountType
could specify whether that user belongs to the front facing public website, or the internal admin website.
For example, the user document:
{
username: "Pavan"
accountType: "administrator"
// other fields below
}
And from there of course, you could publish specific data, or enable different parts of your website based on what accountType
's value is.
For example, if I want the administrators to be able to subscribe to, and see all user information:
Meteor.publish("userData", function() {
if (this.userId) {
if (Meteor.users.find(this.userId).accountType === "admin") {
return Meteor.users.find();
} else {
return Meteor.users.find(this.userId);
}
} else {
this.ready();
}
});
Upvotes: 1
Reputation: 4703
From looking at the source code it appears the collection name is hard coded in the accounts-base
package. I don't see any options to set the name through code.
Meteor.users = new Mongo.Collection("users", {
_preventAutopublish: true,
connection: Meteor.isClient ? Accounts.connection : Meteor.connection
});
Upvotes: 1