2

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.

1
  • Any one has solution for this issue? Commented Nov 16, 2016 at 9:24

2 Answers 2

3

(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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.