Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

query in mongo Shell gives SyntaxError: missing : after property

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!

like image 298
Computerlucaworld Avatar asked Aug 13 '16 07:08

Computerlucaworld


2 Answers

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.

like image 189
adi Avatar answered Nov 03 '22 14:11

adi


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();
like image 29
tarashypka Avatar answered Nov 03 '22 13:11

tarashypka