Match error with genres

I’m getting this error

MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.aggregate(pipeline).itcount()

uncaught exception: Error: command failed: {

“operationTime” : Timestamp(1611380780, 1),

“ok” : 0,

“errmsg” : “Unrecognized pipeline stage name: ‘genres’”,

“code” : 40324,

“codeName” : “Location40324”,

“$clusterTime” : {

“clusterTime” : Timestamp(1611380780, 1),

“signature” : {

“hash” : BinData(0,“UQljLtKFx4L+462RcVmWfkDgI3E=”),

“keyId” : NumberLong(“6863706941324001282”)

}

}

} : aggregate failed :

_getErrorWithCode@src/mongo/shell/utils.js:25:13

doassert@src/mongo/shell/assert.js:18:14

_assertCommandWorked@src/mongo/shell/assert.js:618:17

assert.commandWorked@src/mongo/shell/assert.js:708:16

DB.prototype._runAggregate@src/mongo/shell/db.js:266:5

DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1046:12

@(shell):1:1

here’s my pipeline:
[
{
“$match” : {
“imdb.rating” : {
“$gte” : 7
}
}
},
{
“genres” : {
“$nin” : [
“Crime”,
“Horror”
]
}
},
{
“rating” : {
“$or” : [
“PG”,
“G”
]
}
},
{
“languages” : {
“$and” : [
“English”,
“Japanese”
]
}
}
]
Not sure why I’m getting this error. It’s not recgonizing the genres section of the pipeline. What am I missing?

Essentially, it means that genres is considered a stage of the pipeline. Which it should not since it is a field name. I suspect that you want the genres clause to be part of the $match stage. As it is, genres is outside $match probably because $match is closed too early by having an extra closing brace.

When I try to use the hint to count the aggregtations, I get a fail error that I’m not authorized. How can I check the lab if I can’t access the dbs? I can look at the collections but can’t see what’s inside??
indent preformatted text by 4 spaces

MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.aggregate(pipeline).itcount()

uncaught exception: Error: command failed: {

“operationTime” : Timestamp(1611429501, 1),

“ok” : 0,

“errmsg” : “not authorized on movies to execute command { aggregate: “movies”, pipeline: [ { $match: { idmb.rating: { $gte: 7.0 } } }, { $match: { genres: { $nin: [ “Crime”, “Horror” ] } } }, { $match: { rated: { $or: [ “PG”, “G” ] } } }, { $match: { languages: { $and: [ “English”, “Japanese” ] } } } ], cursor: {}, lsid: { id: UUID(“f6d33b12-3835-492f-9665-ee48de40faa3”) }, $clusterTime: { clusterTime: Timestamp(1611429471, 1), signature: { hash: BinData(0, D0F7269E8EB7AF52DCFAC7BCA41B2D5E4D1F06FA), keyId: 6863706941324001282 } }, $db: “movies” }”,

“code” : 13,

“codeName” : “Unauthorized”,

“$clusterTime” : {

“clusterTime” : Timestamp(1611429501, 1),

“signature” : {

“hash” : BinData(0,“zKlhrQtayy2hM8TmtT7cehIoG4w=”),

“keyId” : NumberLong(“6863706941324001282”)

}

}

} : aggregate failed :

_getErrorWithCode@src/mongo/shell/utils.js:25:13

doassert@src/mongo/shell/assert.js:18:14

_assertCommandWorked@src/mongo/shell/assert.js:618:17

assert.commandWorked@src/mongo/shell/assert.js:708:16

DB.prototype._runAggregate@src/mongo/shell/db.js:266:5

DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1046:12

@(shell):1:1

Hi @Chris_Duff,

use aggregations first, you’re in the database movies.

Apart from that, we never need $match, $match... subsequently, if there are 2 matches one after another, they can be compressed into 1.

Happy coding!

When posting documents, code and command output, please enclosed within 2 lines of triple back ticks ```. This way indentation and proper quotes are preserved.

1 Like

I still cannot pass this test. Even after finally getting no errors when creating the variable I’m still not able to perform the aggregations count. I have some kind of network error.

Then I try to validate the lab and it doesn’t regonize the “genres” stage.

Can you show the connection string you’re using, and a screenshot when you first connect?

Are you not connecting to the sharded cluster and instead to a single node?


This is the string you should be using just in case it helps:

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

Hi @Chris_Duff,

The network error that you are getting might be due to the internet connection. Try reconnecting to the mongo shell using the connection string in the course.

Looking at your aggregation pipeline, it seems that you are using a lot of curly braces which are causing an error. Otherwise, your operators look correct.

Try adding one condition at a time and gradually add more conditions to your pipeline.

Please feel free to reach out if you have any questions.

Kind Regards,
Sonali