How can build 2 meteor apps with 2 different accounts collections (users& admins) in a single database?

Currently i want to build 2 meteor apps, one is for public users, the other one is for admins. And both meteor apps are sharing the same database and collections schema. Because there are some common data that will be accessible for both users and admins.

So i would like to have 2 collections to handle authentication for uses and admins.
In the same database, i already have a users collections for public user authentication.
Now i want to create another collection called admins to handle admins authentication, and hopefully I still can use Meteor.user() to identify if user is logged in.

import { Accounts } from ‘meteor/accounts-base’
Accounts.users = new Mongo.Collection(“admins”);

i have tried the codes as above, then I’m able to call Accounts.createUser() to create admin. However, Meteor.loginWithPassword() will still authenticate with ‘users’ collections instead of ‘admins’ collections

And if i want to overwrite Meteor.users Collection as below
Meteor.users = new Mongo.Collection(“admins”);
This will not help me create ‘admins’ collection

Any ideas how to achieve this? Or is there an official way to do this that I should know? Thanks!

Why not just add a key qualifier in the users collection e.g. isAdmin

1 Like

Don’t want to mix the public users with admins into one collection for management purpose in the future, that’s why i post this look for the solution on how to create 2 different user collections :slight_smile:

As far as I know there is no way to do this - nor can I imagine why you would want to. With simple schema you can define fields that are optional, so if you only wanted to track some fields for admin users you could do that. You could even create a secondary collection which tracks extra information about admin users and link to that by _id from the regular user.

Why do you think you need two collections? Many people have successfully built multi tenant systems with meteor where there are not only public/admin users, but users with entirely separate roles belonging to multiple different clients within the same users collection

1 Like