Hitesh Vaghani
Hitesh Vaghani

Reputation: 1362

How to import/export all collections of the MongoDB database using mongodb java driver?

Is there any function to import and export all collections of mongodb database using java driver.? like there is mongodump and mongorestore using command prompt.

Upvotes: 2

Views: 5033

Answers (4)

Mark Bramnik
Mark Bramnik

Reputation: 42491

The short answer is no. These commands can be invoked only from command line. You might consider to fetch all the data from all collections but its expected to be slow.

You can read a discussion around this here.

Upvotes: 2

boly38
boly38

Reputation: 1955

(same answer as here)

recently I've started a project called mongodbdump-java-wrapper to wrap mongodump.exe and mongorestore.exe mongodb executable from java.

You could clone it from : github project. This project includes integration tests (a way to know how implement backup/restore).

Upvotes: 1

Basker Ammu
Basker Ammu

Reputation: 105

mongodump --host localhost --port 27017 --db sample    

It exacts with folder as dump with database name sample

mongorestore --db sample --verbose d:/dump/sample/

Upvotes: 1

Shivanand Pawar
Shivanand Pawar

Reputation: 547

Well as of now, Mongo Java driver does not support this.

You can try invoking the mongoimport and mongorestore commands from Java Runtime. Like

Runtime.getRuntime().exec("mongoimport -d <dbname> -h <>..");

Upvotes: 0

Related Questions