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> db
Mongo> show collections

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.