14
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!

mr.tarsa
  • 6,386
  • 3
  • 25
  • 42
Computerlucaworld
  • 387
  • 1
  • 2
  • 14

2 Answers2

35

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();
mr.tarsa
  • 6,386
  • 3
  • 25
  • 42
  • 2
    This can also happen if an operator is expection a single argument but you have put it in curly braces. For example `{$sqrt: {$_id}}` is incorrect since it should be `{$sqrt: "$_id"}`. – Ashesh Nov 09 '17 at 15:05
  • 1
    I get the same error running the following command: `rocky26 = Movie.create({:title "Rocky XXVI"})` doesn't mongo generate the ID automatically? – Steven Aguilar Feb 15 '18 at 20:52
  • same error was coming to me at the time of INSERT, fixed it similar way, by adding quotes over inner documents (y) – Vikash Jun 11 '19 at 09:46
8

This error also comes if ":" is missed.

In my case I missed the ":" after $set like the below.

db.myData.updateOne({_id:ObjectId("new_id")},{$set{name:"new_name"}})

I faced the same error mentioned in the title and my changed code that works is

db.myData.updateOne({_id:ObjectId("new_id")},{$set:{name:"new_name"}})

Hope this helps people who did my mistake.

adi
  • 984
  • 15
  • 33