Problems updating The Martian

Here’s the code I copies from the video. The error I keep getting is missing “)”…

db.moveDetails.updateOne({ title: “The Martian”},$set: {“awards”:{“wins”: 8, “nominations”:14,“text”:“Moninated for 3 Globes”}}});

An error message like that usually means your brackets aren’t lining up correctly. In this instance, you have one too many curly brackets at the end of your query. The correct query would be:

db.moveDetails.updateOne({title: “The Martian”}, $set: {“awards”: {“wins”: 8,“nominations”:14,“text”:“Moninated for 3 Globes”}});

It can be hard to keep track of the bracket orders when you write it all on one line. It can be easier to spot and prevent errors when you use JSON-like indentation:

		title: “The Martian”
	}, $set: {
		“awards”: {
			“wins”: 8, 
			“text”:“Moninated for 3 Globes”
1 Like

Thanks for you reply.
I tried copying and pasting both these codes in and I’m still getting following error:
2019-01-12T14:30:54.919-0500 E QUERY [js] SyntaxError: illegal character @(shell):1:clock330:

Try with this line:

db.movieDetails.updateOne({title: "The Martian"}, {$set: {"awards": {"wins": 8,"nominations":14,"text":"Moninated for 3 Globes"}}});

The difference is that your original query (and the one’s I posted) used “Smart Quotes” instead of standard quotes: “ ” instead of " ".

Unfortunately, smart quotes are not valid syntax, but many word processors will convert to smart quotes automatically. It is an easy thing to not notice!

Edit: There were a couple other errors that I noticed, and have updated in my answer above.

  1. You made a typo in the collection name, it should be movieDetails, not moveDetails collection

  2. You need to contain the second parameter of the .updateOne method in a set of curly brackets, so in my first post, it’s not that you had an extra } at the end, it’s that you were missing the first { right before $set.

1 Like

I’d like to comment that I like other indentation styles more than the one used in the videos (one where you can vertically pair up your brackets)

Allman or GNU are fine by me when dealing with so many levels but K&R is, sadly, the standard (based on minimising vertical space for book publication). I always felt that K&R styles seem ashamed of opening brackets …

Hello, I’m having similar issues with this one. When I copy/paste your query I get this in cmd:

{ "acknowledged" : true, "matchedCount" : 0, "modifiedCount" : 0 }

Why is this happening?

I just tested it in my Sandbox, and the query I posted is working for me. Are you sure that you are looking in the video database in your Sandbox Cluster?

If so, are you sure the document for “The Martian” exists in your movieDetails collection? If you type db.movieDetails.findOne({"title": "The Martian"}), does the mongo shell respond with a document?

When I type that in cmd I get null. The document is visible in Compas.

It works. Because of something I needed to switch again to video db. Then I typed db.movieDetails.findOne({“title”: “The Martian”}) and I get the file. After that I typed db.movieDetails.updateOne({title: “The Martian”}, {$set: {“awards”: {“wins”: 8,“nominations”:14,“text”:“Moninated for 3 Globes”}}}) and it works perfect.

Thank you for your help.

Woo! I’m glad it worked for you.

It’s easy to lose track of what database you’re in, it’s happened to me a few times. You can type db to check what database you are in at any time, it can come in handy!

Thank you for this post! I was going mad trying to understand why I kept getting a syntax error. The quotes was my issue.

Pretty sure that was supposed to say “Nominated for 3 Golden Globes”. :slightly_smiling_face: