query in mongo Shell gives SyntaxError: missing : after property

48,426

Solution 1

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();

Solution 2

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.

Share:
48,426
Computerlucaworld
Author by

Computerlucaworld

I like programming and i learn something every day to program better. I think programming is an interesting activity, because you have to think a lot to make efficient programs without bugs.

Updated on March 12, 2021

Comments

  • Computerlucaworld
    Computerlucaworld about 3 years
    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!

  • Ashesh
    Ashesh over 6 years
    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"}.
  • Steven Aguilar
    Steven Aguilar over 6 years
    I get the same error running the following command: rocky26 = Movie.create({:title "Rocky XXVI"}) doesn't mongo generate the ID automatically?
  • Vikash
    Vikash almost 5 years
    same error was coming to me at the time of INSERT, fixed it similar way, by adding quotes over inner documents (y)