Question

I am using an instance of MongoDB with just one node. I would like to write a web service that fsyncs the data files and zips them into a backup folder.

Ideally, I would get the location of the data directory programatically (rather than reading a config file) so I can easily port this from a development to a production machine, where the installation paths differ. Is there any way to do this using the Java driver?

Was it helpful?

Solution

Try using use admin db.runCommand({getCmdLineOpts: 1}) as outlined here and then playing with the returned data.

Example return data is

{
        "argv" : [
                "mongod",
                "--port",
                "6669",
                "--dbpath=c:\\data\\mongo2",
                "--rest"
        ],
        "parsed" : {
                "dbpath" : "c:\\data\\mongo2",
                "port" : 6669,
                "rest" : true
        },
        "ok" : 1
}

OTHER TIPS

You could use mongoexport to get the data; run it from the production machine and specify the host/port/collection of the development machine. The data can be imported to the production machine using mongoimport.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top