Not authorized to execute command

I connect to the aggregations db using the connect string from Chapter One and then any command give the below error . This does not happen all the time only sometimes whats the problem

MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.findOne()
2019-07-01T23:10:07.294-0400 E QUERY [js] Error: error: {
“operationTime” : Timestamp(1562037001, 1),
“ok” : 0,
“errmsg” : “not authorized on movies to execute command { find: “movies”, filter: {}, limit: 1.0, singleBatch: true, lsid: { id: UUID(“4b3dff98-5c53-4af8-b3ca-a0ad5473aac3”) }, $clusterTime: { clusterTime: Timestamp(1562036981, 1), signature: { hash: BinData(0, 8160DD8F0B84F84AE20CB50D38BF2684B7B1B62B), keyId: 6661714504839069697 } }, $db: “movies” }”,
“code” : 13,
“codeName” : “Unauthorized”,
“$clusterTime” : {
“clusterTime” : Timestamp(1562037001, 1),
“signature” : {
“hash” : BinData(0,“4hF0I7KKOvOANnwbbiqECmFlS1A=”),
“keyId” : NumberLong(“6661714504839069697”)
}
}
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DBCommandCursor@src/mongo/shell/query.js:708:1
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

@KarthikMurthy0

If it only happens sometimes, it’s hard to say what’s going on. The next time this happens, type ‘db’ to verify that you’re in the aggregations db. If so, then post all that information here and we’ll try to help. Good luck.

@KarthikMurthy0, my guess is that sometimes you forget to select the aggregation database.