updateMany shows syntax error when running from shell script

My shell script is :

#! /bin/sh
mongo --host 127.0.0.1 << EOF
use data
db.agent.updateMany({},{$set: {“incoming”:-99}})
exit
EOF

On executing this script I get the following error:

E QUERY [thread1] SyntaxError: invalid property id @(shell):1:32


The same commands when run individually on mongo shell execute successfully with the following output
{ “acknowledged” : true, “matchedCount” : 5, “modifiedCount” : 1 }

The shell /bin/sh probably tries to expand $set as a shell variable.

Try to put it inside single quotes.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.