Chapter 1 Basic Aggregation Unauthorized Error

Hello guys need help, I’m getting this not authorized errors. I already checked my port 27017 using this url http://portquiz.net:27017/ and it seems that I don’t have any problems with port 27017. These are the commands I entered and the errors.

Using mongosh

mongosh "mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/aggregations?replicaSet=Cluster0-shard-0" --authenticationDatabase admin --ssl -u m121 --norc

> use mflix
> show collections
MongoServerError: not authorized on mflix to execute command { listCollections: 1, filter: {}, cursor: {}, nameOnly: true, lsid: { id: UUID("e25a396b-67c5-4519-ae66-faf2b387f13b") }, $clusterTime: { clusterTime: Timestamp(1631587013, 1), signature: { hash: BinData(0, B1BA3F71F693397EC13B6FCDEEAC748BB0FADD73), keyId: 6959194651408465922 } }, $db: "mflix", $readPreference: { mode: "primaryPreferred" } } 

Using mongo

mongo "mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/aggregations?replicaSet=Cluster0-shard-0" --authenticationDatabase admin --ssl -u m121 -p aggregations --norc

> use video
> db.movies.findOne()

uncaught exception: Error: error: { "operationTime" : Timestamp(1631587233, 1), "ok" : 0, "errmsg" : "not authorized on video to execute command { find: \"movies\", filter: {}, limit: 1.0, singleBatch: true, lsid: { id: UUID(\"b4179610-5dfc-487c-94b9-a6f3f557c748\") }, $clusterTime: { clusterTime: Timestamp(1631587223, 1), signature: { hash: BinData(0, 9D6608AE8E5560D5C9B502251BED7ECBFB35FA6E), keyId: 6959194651408465922 } }, $db: \"video\" }", "code" : 13, "codeName" : "Unauthorized", "$clusterTime" : { "clusterTime" : Timestamp(1631587233, 1), "signature" : { "hash" : BinData(0,"2Xz9OCmcNVnzW7qVN32OZhnYQqY="), "keyId" : NumberLong("6959194651408465922") } } } : _getErrorWithCode@src/mongo/shell/utils.js:25:13 DBCommandCursor@src/mongo/shell/query.js:711:15 DBQuery.prototype._exec@src/mongo/shell/query.js:113:28 DBQuery.prototype.hasNext@src/mongo/shell/query.js:288:5 DBCollection.prototype.findOne@src/mongo/shell/collection.js:260:10 @(shell):1:1

You should not run the use AnyDatabase command on this cluster with the user m121.

This user has only read access on the aggregations database which is already specified in the URL.

Two ways to go back to normal. Terminate the current shell and reconnect with the connection string. Or, run the command use aggregations in the current shell. I know I wrote that you should not run the use AnyDatabase command but this one is okay.