最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to run mongo --eval? - Stack Overflow

programmeradmin3浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 9

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)

  1. 暂无评论