3

I'm trying to copy between two different DBs on MongoLab using the mongo CLI. I followed the docs - http://docs.mongodb.org/manual/reference/method/db.copyDatabase/

  1. Connected to the target DB.
  2. Ran the following:

    db.copyDatabase('source-db', 'target-db', 'source-host', 'source-user', 'source-pwd')

But I always getting:

{ "ok" : 0, "errmsg" : "unauthorized" }
7
  • Are you on a shared plan? I don't think you can copyDatabase() to a shared destination database there. Commented May 31, 2013 at 11:01
  • both side are non-shared Commented May 31, 2013 at 21:49
  • Then no, I have no idea, only have a shared plan to test with :) Commented May 31, 2013 at 22:00
  • silly question: did you auth to the database with username that has appropriate permissions to run this command? Commented Jun 1, 2013 at 7:50
  • MongoLab has two options User and Read-Only User. How can IC check the permissions? Commented Jun 1, 2013 at 8:44

2 Answers 2

2

I am getting the same error, but when trying to copy a collection:

> db.coll1.copyTo("coll2");
Wed Jul 24 13:32:05 uncaught exception: { "ok" : 0, "errmsg" : "unauthorized" }

My database is on a shared server managed by MongoHQ, so there definitely might be some permission problem there that the service does not allow copyTo or other commands to run.

A simple workaround is to manually fetch all the objects in the collection and insert them to the second collection. This is how things were done prior to copyTo being implemented:

db.coll1.find().forEach(function(o) { db.coll2.insert(o); });
Sign up to request clarification or add additional context in comments.

2 Comments

yes, this is how I solved it, but I don't think it's the most efficient way.
Not efficient, true, but gets the job done. And that's what counts :)
1

you can use mongodump and mongorestore commands instead.

mongodump -h <source_host>:<source_port> -d <source_db> -o ~/tmp/mongodump

mongorestore -h <destination_host>:<destination_port> -d <destination_db> -u <username> -p <password> ~/tmp/mongodump/<source_db>

Comments

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.