3

I am running mongodb 2.4.8 and need to copy a database from remote server. Server has auth enabled in combination with a user having privileges the database. I have tried copydb but it didn't work. I guess it failed because of remote server using auth in combination with role based user(mentioned under authentication section of documentation).

 host = "myhost.com"
 mynonce = db.runCommand( { copydbgetnonce : 1, fromhost: host } ).nonce
 username = "myuser"
 password = "mypassword"
 password_hash = hex_md5(mynonce + username + hex_md5(username + ":mongo:" + password))
 db.runCommand({ 
   copydb: 1, 
   fromdb: "test", 
   todb: "test", 
   fromhost: host, 
   username: username, 
   key: password_hash 
 })
 # output: { "ok" : 0, "errmsg" : "" }
 # but nothing really gets copied

What other options do I have? I would prefer a solution which can work from within the mongo shell as I do not have ssh access to server.

1 Answer 1

2

try db.copyDatabase(fromdb, todb, fromhost, username, password). as manual said: http://docs.mongodb.org/manual/reference/method/db.copyDatabase/

Sign up to request clarification or add additional context in comments.

3 Comments

I tried it first, I received an error stating: not authorized for query on alma_connect.system.users, on adding role userAdmin to the user, I was successfully able to copy the database. Thanks for your help.
FYI, copyDatabse seems to be a shell wrapper around copydb command.
For future readers, db.copyDatabase is "Deprecated since version 4.0"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.