Reputation: 77
I am executing a mongo script in command line with following command.
mongo --quiet --eval remove_audits.js
I want to pass arguments to mongo script like below.
mongo --quiet --eval remove_audits.js arg1 arg2
Let me know how can I do this for mongo script.
Upvotes: 2
Views: 3836
Reputation: 160
I wrote a small utility to solve the problem for myself. With the mongoexec
utility, you would be able to run the command ./remove_audits.js arg1 arg2
by adding the following to the beginning of your script:
#!/usr/bin/mongoexec --quiet
Within the script, you can then access the arguments as args[0]
and args[1]
.
https://github.com/pveierland/mongoexec
Upvotes: 0
Reputation: 100
(repost from MongoDB User email)
There's no way to get the arguments to look exactly like that, but what you can do is use --eval
to pass arguments to your scripts.
Ex:
mongo --quiet --eval 'let arg1="foo", arg2="bar";' remove_audits.js
You can also take a look at this script that I wrote to see an example of how it's done.
Upvotes: 3