dbpath value available from the shell?

604 views
Skip to first unread message

Adam Greene

unread,
Sep 21, 2010, 6:30:31 PM9/21/10
to mongodb-user
Hello,

I would like to be able to retrieve some mongod server configuration
settings, like the dbpath, from within the shell.

is that possible? I couldn't find anything...

thanks,
Adam

Kristina Chodorow

unread,
Sep 21, 2010, 6:32:15 PM9/21/10
to mongod...@googlegroups.com
Yes, check out the {getCmdLineOpts:1} command.



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


Adam Greene

unread,
Sep 21, 2010, 6:34:33 PM9/21/10
to mongodb-user
SWEET! I totally missed it when going over db.listCommands()

thank you kindly!

On Sep 21, 3:32 pm, Kristina Chodorow <krist...@10gen.com> wrote:
> Yes, check out the {getCmdLineOpts:1} command.
>
>
>
>
>
>
>
> On Tue, Sep 21, 2010 at 6:30 PM, Adam Greene <adam.gre...@gmail.com> wrote:
> > Hello,
>
> > I would like to be able to retrieve some mongod server configuration
> > settings, like the dbpath, from within the shell.
>
> > is that possible?  I couldn't find anything...
>
> > thanks,
> > Adam
>
> > --
> > 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<mongodb-user%2Bunsubscribe@google groups.com>
> > .

Kristina Chodorow

unread,
Sep 21, 2010, 6:41:02 PM9/21/10
to mongod...@googlegroups.com
No problem :)


To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.

Adam Greene

unread,
Sep 21, 2010, 7:01:27 PM9/21/10
to mongodb-user
ah, well, that doesn't always do it. if the --config flag is passed,
then it is usually stored in there. so getCmdLineOpts gets me most of
the way there, but not quite. If dbpath isn't available anywhere else,
I can parse through the attached config file.

thanks Kristina,
Adam

Adam Greene

unread,
Sep 21, 2010, 7:40:51 PM9/21/10
to mongodb-user
well, this works (in ruby) ;)


cmd = "mongo --quiet --eval 'printjson(db.runCommand({getCmdLineOpts:
1}));' admin"
output = JSON.parse(`#{cmd}`)
db_path = output['argv'][output['argv'].index('--dbpath') + 1] if
output['argv'].index('--dbpath')
db_path ||= $1 if File.read(output['argv'][output['argv'].index('--
config') + 1]) =~ /dbpath\s*=\s*([^\s]*)/


this is starting to get ugly, but hey, no complaints!
Reply all
Reply to author
Forward
0 new messages