开发者

How to run mongo --eval?

开发者 https://www.devze.com 2023-02-08 04:13 出处:网络
I run mongo --helpand it has an options for evaluate javascript. 开发者_Go百科mongo --evalarg However, I haven\'t found any example of how to use it. I try to run it but with no success.anyone know

I run mongo --help and it has an options for evaluate javascript.

开发者_Go百科
mongo --eval  arg

However, I haven't found any example of how to use it. I try to run it but with no success. anyone know how to do it?

the reason is that, I want to delete a collection through command line ( so that I can reuse the code and put it into shell script). I know I can write another nodejs and call the db to run it.. but instead of 20 lines of code, it would be nice if there is a solution with only few lines and be faster. :)


That would be:

mongo <server>:<port>/<database> --eval "db.<some_collection>.drop();"

Or if you want to do something in more lines you can call a file (must end with .js):

mongo <server>:<port>/<database> some_instructions.js
0

精彩评论

暂无评论...
验证码 换一张
取 消