Not Authorized on <dbName> to execute Command

Hi all,
I just began working on the first lab and I followed all the instructions mentioned in the chapters. when I connect to the MongoDB cluster with the string provided in chapter zero and try to query the movies db, I am getting the following error every time I try to execute the same command.
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.findOne()
2019-07-18T22:35:25.353-0230 E QUERY [js] Error: error: {
“operationTime” : Timestamp(1563498318, 1),
“ok” : 0,
“errmsg” : “not authorized on movies to execute command { find: “movies”, filter: {}, limit: 1.0, singleBatch: true, lsid: { id: UUID(“8c88e963-baea-44f1-8ff2-736db742f4d2”) }, $clusterTime: { clusterTime: Timestamp(1563498318, 1), signature: { hash: BinData(0, 16845D1D7DF636C21BEDE423C57940932ADABD28), keyId: 6661714504839069697 } }, $db: “movies” }”,
“code” : 13,
“codeName” : “Unauthorized”,
“$clusterTime” : {
“clusterTime” : Timestamp(1563498318, 1),
“signature” : {
“hash” : BinData(0,“FoRdHX32NsIb7eQjxXlAkyravSg=”),
“keyId” : NumberLong(“6661714504839069697”)
} :

Experts: Do we need to provide admin access to the user used in the String or it is some different item I need to do before I execute the above operation?

Most likely you are in wrong DB
Please double check your connect string
Did you change the db by use db?
i think by default you will be connected to aggregations DB with supplied string

I am using the following string to connect
mongo “mongodb://,,” --authenticationDatabase admin --ssl -u m121 -p aggregations --norc

I have not changed any of the items above.


But did you then try to change the database using a ‘use’ command? Once you are connected to the Atlas cluster, I suggest that you use the ‘db’ command – you will see that you are already in the ‘aggregations’ database. The error you are getting is because you are NOT in the ‘aggregations’ database. If you do not try to change the database, you will not have any error. Good luck,

1 Like