query in mongo Shell gives SyntaxError: missing : after property

Computerlucaworld picture Computerlucaworld · Aug 13, 2016 · Viewed 41.5k times · Source
db.movieDetails.find(
  { year: 2013, imdb.rating: Pg-13, award.wins: 0 },
  { title: 1, _id: 0 }
).pretty();

The mongo shell returns this error

2016-08-13T09:08:00.648+0200 E QUERY [thread1] SyntaxError: missing : after property id @(shell):1:60

Why? Thank you in advance!

Answer

tarashypka picture tarashypka · Aug 13, 2016

If your query includes inner documents, then use quotes for them. Also, use quotes for querying String values

db.movieDetails.find(
  { year: 2013, "imdb.rating": "Pg-13", "award.wins": 0 },
  { title: 1, _id: 0 }
).pretty();