MongoDB user management

41 Views Asked by At

I have two replica set, the primary one I want to disable all users and just the application login will connect to it and on the secondary I want the user to connect it to secondary for reading purpose. I do not want any one to connect with primary replication other than the application. Can this be achievable, please guide.

Like we can achieve this type of solution by SQL Server, I want to implement same in mongodb.

1

There are 1 best solutions below

1
On

I don't think that's possible. In general all data in a replica set are replicated, i.e. they are exactly the same - this includes also user/role details.

Maybe it would be possible to create local users, however by default you don't know which node acts as PRIMARY or SECONDARY (unless you set Priority 0).

How do the user connect to your MongoDB? Maybe you can rewrite their connection URL with and append readPreference=secondaryPreferred

Update:

I don't think the local user will work. You can drop the entire node and connect it to replica set with an empty data directory. The initial synch will copy all data to the new node, i.e. it would also overwrite any locally created user account.