Homework Issue - $match

hello,
I cannot execute show.collections and db.movies.findOne() after execute command below. Does anyone idea about issue?

MongoDB Enterprise Cluster0-shard-0:PRIMARY> var pipeline =  [ { $match: {} } ]
MongoDB Enterprise Cluster0-shard-0:PRIMARY>db.movies.aggregate(pipeline).itcount()

What is the error message?

Hi @Beytullah_48478,

In addition to this, please share the connection string that you have used to connect to the cluster.

Thanks,
Sonali

MongoDB Enterprise Cluster0-shard-0:PRIMARY> use admin
switched to db admin
MongoDB Enterprise Cluster0-shard-0:PRIMARY> show collections
Warning: unable to run listCollections, attempting to approximate collection names by parsing connectionStatus
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.find().pretty()
Error: error: {
        "operationTime" : Timestamp(1576820366, 1),
        "ok" : 0,
        "errmsg" : "not authorized on admin to execute command { find: \"movies\", filter: {}, lsid: { id: UUID(\"875865f1-e353-4aa2-a3ac-bb1bf09b19a5\") }, $clusterTime: { clusterTime: Timestamp(1576820346, 1), signature: { hash: BinData(0, E44B874BDA1BCE4225759EDBDC9E6B3F3BA29F1E), keyId: 6730992026675838977 } }, $db: \"admin\" }",
        "code" : 13,
        "codeName" : "Unauthorized",
        "$clusterTime" : {
                "clusterTime" : Timestamp(1576820366, 1),
                "signature" : {
                        "hash" : BinData(0,"Fbvrv5qV3VWi3v2UuGTmPaJPAaA="),
                        "keyId" : NumberLong("6730992026675838977")
                }
        }
}
MongoDB Enterprise Cluster0-shard-0:PRIMARY> use video
switched to db video
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.find().pretty()
Error: error: {
        "operationTime" : Timestamp(1576820386, 1),
        "ok" : 0,
        "errmsg" : "not authorized on video to execute command { find: \"movies\", filter: {}, lsid: { id: UUID(\"875865f1-e353-4aa2-a3ac-bb1bf09b19a5\") }, $clusterTime: { clusterTime: Timestamp(1576820386, 1), signature: { hash: BinData(0, BD8296494158FADB56E76077B13E28BBAE6F91A6), keyId: 6730992026675838977 } }, $db: \"video\" }",
        "code" : 13,
        "codeName" : "Unauthorized",
        "$clusterTime" : {
                "clusterTime" : Timestamp(1576820386, 1),
                "signature" : {
                        "hash" : BinData(0,"vYKWSUFY+ttW52B3sT4ou65vkaY="),
                        "keyId" : NumberLong("6730992026675838977")
                }
        }
}
MongoDB Enterprise Cluster0-shard-0:PRIMARY> quit()

Hi @Beytullah_48478,

You would have connected to the cluster using the following connection string:

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

The m121 user has only permissions over aggregations database and using the above connection string you are connected to aggregations database.

So, if you want to access movies collection, follow the steps below:

use aggregations
show collections
db.movies.find()

Please check the screenshot below:

Note: You cannot access any other database except aggregations.

Please let me know, if you have any questions.

Thanks,
Sonali

I got it . thanks a lot.