M121 Chaper 1: Homework 1 $match "not authorized on movies to execute command"

Hello

I successfully connected to the db, but when I try to query db.movies, I get the following auth error in cmd:

MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.find(
… {“imdb.rating”: {$gte:7}})
Error: error: {
“operationTime” : Timestamp(1573679630, 1),
“ok” : 0,
“errmsg” : “not authorized on movies to execute command { find: “movies”, filter: { imdb.rating: { $gte: 7.0 } }, lsid: { id: UUID(“6c321406-6a55-4dbf-a080-1027467772c1”) }, $clusterTime: { clusterTime: Timestamp(1573679590, 1), signature: { hash: BinData(0, E7A8DB4419BE9317BF9162430CC5862FD48A98FE), keyId: 6730992026675838977 } }, $db: “movies” }”,
“code” : 13,
“codeName” : “Unauthorized”,
“$clusterTime” : {
“clusterTime” : Timestamp(1573679630, 1),
“signature” : {
“hash” : BinData(0,“kX5xNSvIbcmlTVTOxWtIdQg3ybg=”),
“keyId” : NumberLong(“6730992026675838977”)
}
}
}

I’m trying to test my operators before I create the pipeline var. But I’m not even getting that far.

Thank you
Nicholas

Did you run USE before? So you are quering the correct DB - as the user will have very strict privileges. So I would ensure that you are on the correct cluster and correct DB (and reading the right collection)

Thank you @azor.haf for responding. Yes, I first used, “use movies”

Are you sure about that :
use aggregations
db.movies….

Actually you should comment out (so please edit the post) the filters from the first question - It looks like close-like answer from the homework.

I deleted my .find() in case it’s too close to the answer

1 Like

I’m not sure what you’re saying, use aggregations?

I have done the course a long time ago, not sure about the homework but instruction from some lessons is “Once you’ve connected, list the existing collections of the aggregations database. Your output should be similar to this one:”

There is a movies database with / or without movie collection.
But you should likely run that on aggregation db which containts movies collection
so not use movie to switch to movie db but use aggregations to use db for the course I belive

also on aggregations db you can run list collection commands which you cannot do with this user on movies db.

I’m not sure that’s correct, because this is one of the hints on the homework:

“As a hint, your aggregation should return 23 documents. You can verify this by typing db.movies.aggregate(pipeline).itcount()”

db.movies .aggregate(pipeline).itcount()
This is COLLECTION movies you run aggregate on.
It does not refer / show if “db” is in movies database or in aggregations DATABASE. What I am saying you have access on movies collection in aggregations database, not in movies database.

1 Like

I’ll be honest, I don’t 100% understand. But I tried what you said, and I’m starting to see results. So thank you @azor.haf. I’m going to continue to try doing this and see if I come up with the correct answer.

Mongod can contains one or more databases, to check that run:
show dbs
You will see:
aggregations
movies
citybikes
local
and other mess.

These are databases. Every database can have its own collections. So first you need to start by picking up the database:
use aggregates
or
use movies
or
use local
once you are inside the database you can run show collections to see collections (if you have privileges)

use aggregations
show collections

Then you run your command
db.movies.find()
where: db is always db and it represent current database context you are running the query
and then movie that is name of the collection.

So there is now:
Database: Aggregations containing Movies collection (the one you should use)
Database Movies may or may not containing movies collection (as you do not have privileges to see that)

I see, I’m able to query the movies collection on the aggregations db. getting results, thank you!