Trouble invoking MongoDB update using shell –eval switch from Powershell

Question:

I am trying to invoke a MongoDB javascript fragment using the mongo.exe –eval command line switch. This works fine when run from the Windows command line, but I want to invoke it from a Powershell script like so:

There is only one document in the mydata collection, and I want to set its v field to 1. But, the above expression returns SyntaxError: invalid property id (shell eval):1 when run from a Powershell script and does not update the document.

What makes this even more confusing is that the follow works as expected:

Any ideas what I might be doing wrong?

Update:

The solution:

Answer:

Try using single quotes instead of double quotes around the eval statement.

Source:

Trouble invoking MongoDB update using shell –eval switch from Powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply