This works within the mongo terminal
$ mongo datas
> db.mydb.update({},{$set : {'ids.my_key':''}}, {multi:true})
But fails when eval'd from the command line.
mongo datas --eval "db.mydb.update({},{$set : {'ids.my_key':''}}, {multi:true})"
MongoDB shell version: 2.4.5
connecting to: datas
Thu Dec 12 12:35:24.063 JavaScript execution failed: SyntaxError: Unexpected token :
I assume it's quote-related, but haven't been able to get it to work.
The problem is not mongo shell, it is your OS shell which is trying to interpret some of the characters you are wanting to pass to mongo. Try the same syntax but with single quotes around the entire expression and double quotes inside:
$ mongo datas --eval "db.mydb.update({},{$set : {'ids.my_key':''}}, {multi:true})"
MongoDB shell version: 2.4.5
connecting to: datas
Thu Dec 12 18:14:22.049 JavaScript execution failed: SyntaxError: Unexpected token :
$ mongo datas --eval 'db.mydb.update({},{$set : {"ids.my_key":""}}, {multi:true})'
MongoDB shell version: 2.4.5
connecting to: datas
$
Try to update mongo shell version: script executed successfully on 2.4.8.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With