Updating a document by inserting an object with updateOne

Hello everyone
I’m following the instructor’s example on chapter 2: update operators, but I keep getting the following error: [js] SyntaxError: missing ; before statement @(shell):1:46

Below is the query the instructor is using (I’m using the same):

let text2 = [‘Best movie of the year’].join() db.movieDetails.updateOne({‘title’: ‘The Martian’}, {$push:{‘reviews’:{‘ratings’: 4.5, ‘date’: ISODate(‘2020-10-12T11:50:00Z’), ‘reviewer’: ‘Alpha Ly’, ‘text’: text2 }}})

What am I doing wrong?


At least on my laptop, Mongo shell complains about single quotes, so you can try using double quotes instead. The particular error comes from the colon after ‘title’. I would also add a semicolon ; after join().

(side-comment: you can format your code surrounding by 3 backticks ``` so it’s formatted as a block level code snippet, and it’s easier to read.)

1 Like

@Santiago_Miranda Thanks for your input.
but why no colon after ‘title’?
That seems to be the syntax used by the instructor from the beginning I believe.
Would you please paste whatever you put on your shell so I can what you’re referring to?

1 Like

Sure. I’d rewrite the command like this:

let text2 = ["Best movie of the year"].join();
db.movieDetails.updateOne({ "title": "The Martian"}, 
    "ratings": 4.5,
    "date": ISODate("2020-10-12T11:50:00Z"),
    "reviewer": "Alpha Ly",
    "text": text2 

You can use single quotes if you prefer, but not the rare single quotes you’re using (that seems to be another type of quotes other than the standard ones).

Good luck for the next steps!

1 Like

@Santiago_Miranda thank you. I’ll try this