how to pass command line arguments to mongo shell script

6,141 views
Skip to first unread message

Srimonti

unread,
Feb 29, 2012, 8:28:40 PM2/29/12
to mongodb-user
I would like to do

./mongo dbname myscript.js --myparam value

where myparam would be passed to myscript as a command line argument.

Is this possible?


Thanks,
Srimonti

Eliot Horowitz

unread,
Mar 1, 2012, 8:08:19 AM3/1/12
to mongod...@googlegroups.com
There isn't a way currently but its something we want to add.
Can you make a jira case @ jira.mongodb.org to ensure we don't forget :)

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>

Raxit Sheth

unread,
Mar 1, 2012, 8:25:32 AM3/1/12
to mongod...@googlegroups.com
may be quick workaround is to call mongodb script from external
scripting language like perl/python/ruby/bash, which will do
pre-processing.

Srimonti

unread,
Mar 1, 2012, 8:43:29 AM3/1/12
to mongodb-user
Thanks Eliot. I will do that.

Srimonti

unread,
Mar 1, 2012, 8:44:22 AM3/1/12
to mongodb-user
Worth a try. Thanks Raxit.

On Mar 1, 8:25 am, Raxit Sheth <raxitsheth2...@gmail.com> wrote:
> may be quick workaround is to call mongodb script from external
> scripting language like perl/python/ruby/bash, which will do
> pre-processing.
>
>
>
>
>
>
>
> On Thu, Mar 1, 2012 at 6:38 PM, Eliot Horowitz <el...@10gen.com> wrote:
> > There isn't a way currently but its something we want to add.
> > Can you make a jira case @ jira.mongodb.org to ensure we don't forget :)
>
> > On Wed, Feb 29, 2012 at 8:28 PM, Srimonti <skarma...@gmail.com> wrote:
> >> I would like to do
>
> >> ./mongo dbname myscript.js --myparam value
>
> >> where myparam would be passed to myscript as a command line argument.
>
> >> Is this possible?
>
> >> Thanks,
> >> Srimonti
>
> >> --
> >> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> >> To post to this group, send email to mongod...@googlegroups.com.
> >> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> >> For more options, visit this group athttp://groups.google.com/group/mongodb-user?hl=en.

Tad Marshall

unread,
Mar 1, 2012, 8:18:05 PM3/1/12
to mongodb-user
Another workaround is to combine --eval with your JavaScript file on
the command line, for example:

$ cat addthem.js
printjson( param1 + param2 );
$ ./mongo --nodb --quiet --eval "var param1=7, param2=8" addthem.js
15

Raxit Sheth

unread,
Mar 2, 2012, 1:47:26 AM3/2/12
to mongod...@googlegroups.com
Will it lock down other stuff ? i guess
Reply all
Reply to author
Forward
0 new messages