admin管理员组文章数量:1320595
I run mongo --help and it has an options for evaluate javascript.
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 mand 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. :)
I run mongo --help and it has an options for evaluate javascript.
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 mand 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. :)
Share Improve this question edited Dec 6, 2018 at 13:36 Cœur 38.8k26 gold badges205 silver badges277 bronze badges asked Feb 3, 2011 at 18:20 murvinlaimurvinlai 50.4k54 gold badges133 silver badges177 bronze badges1 Answer
Reset to default 9That 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
本文标签: javascriptHow to run mongo evalStack Overflow
版权声明:本文标题:javascript - How to run mongo --eval? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742085452a2419947.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论