Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
59 views
in Technique[技术] by (71.8m points)

How do I copy a database from one MongoDB server to another?

I have two mongodbs in different server, both start with --auth. Now I want to copy a db from one server to another.

> mongo
> use admin
> db.copyDatabase("mydb","mydb","another_server")

It shows:

{ "errmsg" : "", "ok" : 0 }

And:

> db.getLastError()
null

Seems no error, but the copy is not successful. What's the correct command to use?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you are using --auth, you'll need to include your username/password in there...

Also you must be on the "destination" server when you run the command.

db.copyDatabase(<from_db>, <to_db>, <from_hostname>, <username>, <password>);

If all that doesn't work, you might want to try something like creating a slave of the database you want to copy ...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...