User is not allowed to do action [listCollections]

I’m trying the mongodb basics course, in chapter 2 when I try to complete the quiz I’m getting this error.

MongoDB Enterprise atlas-qgf96i-shard-0:PRIMARY> show collections
uncaught exception: Error: listCollections failed: {
        "ok" : 0,
        "errmsg" : "user is not allowed to do action [listCollections] on [sample_training.]",
        "code" : 8000,
        "codeName" : "AtlasError"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype._getCollectionInfosCommand@src/mongo/shell/db.js:808:15
DB.prototype.getCollectionInfos@src/mongo/shell/db.js:856:16
shellHelper.show@src/mongo/shell/utils.js:924:9
shellHelper@src/mongo/shell/utils.js:819:15
@(shellhelp2):1:1
MongoDB Enterprise atlas-qgf96i-shard-0:PRIMARY> db.trips.find({})
Error: error: {
        "ok" : 0,
        "errmsg" : "user is not allowed to do action [find] on [sample_training.trips]",
        "code" : 8000,
        "codeName" : "AtlasError"
}

Hi @Sai_Pratap_P, and welcome to the MongoDB Community forums! :wave:

Are you connecting to the Atlas cluster that you created in Chapter 1: Lab: Create and Deploy an Atlas Cluster, with the user credentials you set up?

The error you’re getting is that the user you’ve authenticated with (you might even have connected to your cluster without authenticating) does not have the proper privileges to perform the actions you’re trying to do.

Try running db.runCommand({connectionStatus: 1}) to see who you have authenticated as. If you’re not authenticated, you would see something like the following:

→ db.runCommand({connectionStatus: 1})
{
  authInfo: { authenticatedUsers: [], authenticatedUserRoles: [] },
  ok: 1
}

If you are authenticated, you should something like the following:

 → db.runCommand({connectionStatus: 1})
{
  authInfo: {
    authenticatedUsers: [ { user: 'test', db: 'admin' } ],
    authenticatedUserRoles: [ { role: 'readWriteAnyDatabase', db: 'admin' } ]
  },
  ok: 1
}

The result of this command will help troubleshoot the issue you are having.

1 Like

Thank you @Doug_Duncan working fine now :blush:

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.