Comparison Operators Quiz, testing projections

Everything is fine with the quiz. But I tried to test projections with the QUERY, and didn’t work. I tried to match the writers Ethan and Joel Coen, but instead to get only the count, I wanted to get just the title and writer fields.

db.movieDetails.find({'writers': {$in: ['Ethan Coen', 'Joel Coen']}}).pretty()

Where should I place the {‘title’:1, ‘writers’:1, ‘_id’:0}?

db.movieDetails.find({‘writers’: {$in: [‘Ethan Coen’, ‘Joel Coen’]}, {‘title’:1, ‘writers’:1, ‘_id’:0}}).pretty()

After the $in block didn’t work. Got this error:

2019-04-18T14:22:51.344-0300 E QUERY [js] SyntaxError: invalid property id @(shell):1:69

I don’t think you need to put ’ ’ on title, _id, and writers.

1 Like

Hello,

try to use:
db.movieDetails.find({writers:{$in:[“Ethan Coen”, “Joel Coen”]}}, {_id:0, title:1, rated:1})

1 Like

Thanks Sonia! I got it. It was missing some curly braces after Joel Coen! I’m still not used to the amount of curly braces in a linear fasion. It makes sense after several break lines, like in the javascript code or in the Python Dictionaries…

There were some Curly braces missing after Joel Coen. Need to get used to it!. Thanks a lot.

Regarding the excess of <’ '>, they changed the way mongodb is working. It’s a little annoying have to type then. But it’s necessary after “movies.details” and when you are selecting fields. So I started to place them everywhere. It Also works on the operators. Although in compass if you don’t use them, the software starts the suggestions drop down menu.

Again thanks a lot for your answer!

I used this exact query and I keep getting an error:
SyntaxError: illegal character @(shell):1:31

That may be because of quotes
Did you cut & paste that command?

MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movieDetails.find({writers:{$in:[“Ethan Coen”, “Joel Coen”]}}, {_id:0, title:1, rated:1})
2019-05-09T13:06:31.951+0530 E QUERY [js] SyntaxError: illegal character @(shell):1:36

First attempt failed as double quotes came as inverted commas when you cut & paste command

2nd attempt typed double quotes ad it worked
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movieDetails.find({writers:{$in:[“Ethan Coen”,“Joel Coen”]}}, {_id:0, title:1, rated:1})
{ “title” : “The Big Lebowski”, “rated” : “R” }
{ “title” : “No Country for Old Men”, “rated” : “R” }
{ “title” : “Paris, je t’aime”, “rated” : “R” }
MongoDB Enterprise Cluster0-shard-0:PRIMARY>

Just found my problem. Such a silly mistake :sweat_smile:
I was hitting the § key instead of $ on my keyboard.
Thanks!