Not authorized on movies to execute command

When i try to run following command
db.movies.aggregate([{ $match : {“imdb.rating” : { $gte: 7 } } } ] ).pretty();

It give following message

MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.aggregate([{ $match : {“imdb.rating” : { $gte: 7 } } } ] ).pretty();
assert: command failed: {
“operationTime” : Timestamp(1550429422, 95),
“ok” : 0,
“errmsg” : “not authorized on movies to execute command { aggregate: “movies”, pipeline: [ { $match: { imdb.rating
c8d341-7cc6-4f65-bc8a-6089abcf1287”) }, $clusterTime: { clusterTime: Timestamp(1550429329, 1), signature: { hash: BinData(0
672121604571137 } }, $db: “movies” }",
“code” : 13,
“codeName” : “Unauthorized”,
“$clusterTime” : {
“clusterTime” : Timestamp(1550429422, 95),
“signature” : {
“hash” : BinData(0,“mTFvqEGor4pofnAYYj6rK0EHR3s=”),
“keyId” : NumberLong(“6627672121604571137”)
}
}
} : aggregate failed
_getErrorWithCode@src/mongo/shell/utils.js:25:clock1130:

@ Aseem_40292

Notice that you should be in the database aggregations and the collection movies. Check where you are using the db command.

2 Likes

Just to add to this as I’ve encountered this error and was about to ask the same question, you get to the correct database by simply…

> use aggregations
> show collections 

Having come from M001 I was mistakenly doing the following which you do not have to do as for M121 movies is a collection within the aggregations db…

use movies