Link to home
Start Free TrialLog in
Avatar of Brandon Lyon
Brandon Lyon

asked on

How to fix a Mongo typo

Hi,
I'm new to mongodb. How would I fix a typo in an object? I tried this query but it resulted in an error of "Unexpected token ILLEGAL"

db.mer22.update({_id:12345},{$set{"yDescription":"Candy"}})

Open in new window

Avatar of Brandon Lyon
Brandon Lyon

ASKER

Rather than update using a $set command I was able to go a different route. I overwrote the entire json entry. This wasn't ideal but it did the trick.

db.mer22.update({_id:12345},{yDescription:"Candy",yColor:"red",ySize:"103"})

Open in new window

To me, it looks like the original problem might have been the quotes around yDescription.
If I don't have the quotes around yDescription then the error I get is "SyntaxError: Unexpected token {"

db.mer22.update({_id:12345},{$set{yDescription:"Candy"}})

Open in new window

My solution is more of a workaround than an actual solution. It's not even a technically correct solution. Instead of updating a single value, I overwrote all of the values. I'd still like to learn how to update just a single value.
ASKER CERTIFIED SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you, that did the trick! I was missing a colon after the set.