1

I am trying to update a mongoDb collection via ssh from a shell script but getting the below error :

MongoDB shell version: 2.6.4 connecting to: localhost:27017/b2b_tempdb 2017-12-05T11:04:51.153+0000 SyntaxError: Unexpected token :

Below is the full command :

ssh -n happy@localhost  " mongo --host localhost:27017  --authenticationDatabase admin b2b_tempdb --eval 'db=db.getSiblingDB( \"b2b_tempdb\" ); db[\"b2b_tempdb.activity.preferences\"].update({},{ $set: {'codeId':\"happy.l2l-09l2l121\"} }, {multi:true})' "

Kindly help me in getting it resolved . Thanks in advance for the help .

  • Why not you are using 'MongoDB Compass' . If you are using SSH. Are you using 'Local' or 'Remote' Database. – Md Haidar Ali Khan Dec 5 '17 at 12:05
  • Not allowed to use any separate product here in the project . am trying to connect to a remote machine where MongoDb is installed . Thanks – Abhishek kumar Dec 5 '17 at 12:14
  • what is your O.S environment? – Md Haidar Ali Khan Dec 5 '17 at 12:23
1

For me this works fine

ssh mongodb.domain.com "mongo --eval='db.getSiblingDB(\"testi\").empty.update({},{\$set:{key:1}},{multi:true})'"

The catch is \ before $ because otherways shell will "expand" that $set "enviroment variable", what of course don't exists.

  • As per OP the error shows that he is using "localhost". – Md Haidar Ali Khan Dec 7 '17 at 8:14
  • You can ssh to localhost and use localhost as host in mongo... No problem. So, my aswer works fine even I replace that mongodb.domain.com with localhost. – JJussi Dec 7 '17 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.