[Lab 1] Can filter the 23 movies with find, but get syntax error when using match

Hi there,

I’ve been stuck a few hours on this. Have tried reading up on other threads for lab 1, but couldn’t find much that helped. I have concocted a find command with all the conditions specified in the lab. It does indeed return a 23 count. The command is as followed (filters edited out by underscores).

 db.movies.find({$and: [
 {genres : {_},{"imdb.rating" : {_}}, {"rated": {_}, {"languages": {_}]}).count()

So this command works. Now, I try to adapt this to a $match command with the following syntax:

db.movies.aggregate(
    [ { $match : {  } } ]
);

Which leads me to something like this:

db.movies.aggregate(
    [ { $match : {genres : {_}},{"imdb.rating" : {_}}, {"rated": {_}}, {"languages": {_}}} ]
);

Now when I run that command I get the following error:
2019-08-24T22:27:02.411+0300 E QUERY [js] SyntaxError: invalid property id @(shell):1:73

I’ve checked plenty of times the parenthesis/brackets, to no avail.

Any tips?

Much appreciated

1 Like

@Lolo_40041 Nice way to share! Thank you

Your close!
Try this…

db.movies.aggregate([
  {
    $match: {
      genre: { expression },
      rated: { expression },
      ...
    }    
  }
])

Compared to yours

db.movies.aggregate([
  {
    $match: {
      { genre: { expression } },
      { rated: { expression } },
      ...
    }    
  }
])
1 Like

I am at the same point but I get an errmsg "“not authorized on movies to execute command { aggregate: “movies”, pipeline: …”

@eliasjamal

Could be a couple things:

Are you using the correct db?

use aggregations
db.movies.aggre...

And have you connected with the correct username and password 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

And I am only curious. Are you using this?

db.runCommand({})

that worked thank you.

the db.movies.aggregate(pipeline).itcount() - I received an “Error:command failed: {”
but “pipeline.itcount()” returned the count of 23