MongoDB permission to view collections not working I have 2 dbs:


admin
ops


I have a user with a readWriteAnyDatabase role but he cannot list the collections in the ops db.

I have another user with a root role and he succeeded in listing the collections for the ops db.

I try to view the collections in ops

The error I am getting:


  Not authorized to execute command: listCollections...


using mongodb: 3.4.7

In the mongoDB config I only added auto=true.

What can be the cause?
You need to give that "readWriteAnyDatabase" role to the user for "admin" database.

use admin
db.createUser({user:"test", pwd:"test", roles: ["readWriteAnyDatabase"]})


after that you can login with that user and see all collections

mongo -u test -p test --authenticationDatabase admin opt
Mongo&gt; db
opt
Mongo&gt; show collections
test_collection
Mongo&gt;