I want to setup a user in MongoDB. This user will not have admin database access. But it uses admin as authentication database. It will fail to connect the mongoDB by this command mongo --host localhost admin
. Instead, it can use this command to connect to test
database: mongo --host localhost --authenticationDatabases admin test
. How can I restrict the permission in this case?
I tried below command to create an user:
db.createUser({user: 'testUser', pwd: '123456', roles: [{role:'readWrite', db: 'SampleCollections'}]})
when I use that user account to login mongo shell, I am able to list the databasescollections under admin
database. How can I restrict the user only on SampleCollections
database not admin
?