Chapter 2: Getting error in Update Many Lesson

Am getting the following error when i am executing the update many query.
Query:
db.movieDetails.updateMany({ rated: null }, { $unset : { rated: “” }})

Error:
2020-02-02T18:05:08.919+0100 E QUERY [js] uncaught exception: SyntaxError: illegal character :
@(shell):1:64

I know that the error is on the 64th character and that is the colon after rated but i don’t know what’s going wrong here.

Thanks

So, I solved the issue. In case if anyone else faces it.

db.movieDetails.updateMany({
    rated: null
}, {
    $unset : {
    rated:' '}})

just replace the double quotes " " with single quotes ’ ’

I don’t know whats the logic behind it but it fixed my issue.

Thanks

If you look very closely at the double quotes you have after rated when you had the exception you will notice that they are not real double quotes. Some editors, when not in code writing mode, produced different kind of matching back and forward double quotes.

Bad : “ and ”
Good : " and "
Good : ’ and '

That is not mongo specific. That’s JavaScript (and most programming languages) specific.

2 Likes

Thanks mate … its really helpful

Closing this thread as the issue has been resolved.