Pass arguments to mongo script

1,152 views
Skip to first unread message

Abhishek Upadhyay

unread,
Nov 16, 2016, 5:53:31 PM11/16/16
to mongodb-user

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.

Matt Cotter

unread,
Nov 17, 2016, 11:21:18 AM11/17/16
to mongodb-user
Hello!

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.

Best,
-Matt

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/e181d600-34c1-460f-8818-dbd6a16898ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages