R
R
Rustem Vorozheikin2015-05-27 17:44:28
Python
Rustem Vorozheikin, 2015-05-27 17:44:28

How to copy mongo database from server using pymongo?

Hello.
Created a user at the base "admin" in mongo. I pointed out to him all the rights that I found. mongo version 2.4.9

{
  "_id" : ObjectId("5565d4b0e2cb3c06a51bc810"),
  "user" : "root2",
  "pwd" : "83649f9cf3fc01bd7dce347baf12e838",
  "roles" : [
    "read",
    "readWrite",
    "dbAdmin",
    "userAdmin",
    "clusterAdmin",
    "readAnyDatabase",
    "readWriteAnyDatabase",
    "userAdminAnyDatabase",
    "dbAdminAnyDatabase"
  ]
}

My attempt to copy the code:
import pymongo
from pymongo import MongoClient
client2 = MongoClient('52.74.52.245', 27017)
client2.admin.authenticate('root2', 'password')
print(client2.shoppr_db.collection_names())
client = MongoClient()
client.admin.command(
          'copydb',
          fromdb='shoppr_db',
          todb='del4',
          fromhost='52.74.59.245',
          username='root2',
          key='83649f9cf3fc01bd7cce347baf22e838'
          )

The names of the collection are displayed as expected. But when trying to copy the database, an error occurs:
,,,on namespace admin.$cmd failed: exception: nextSafe(): { $err: "not authorized for query on shoppr_db.system.namespaces", code: 16550 }

I never found the manual where to enter the password. More precisely, I found that it seems that you need to specify the "hash" of the password in the key field. I thought that the "hash" field is the string "pwd" : "83649f9cf3fc01bd7dce347baf12e838", which was displayed after user registration.
The shoppr_db database also has its own user "user" with read permissions (If it matters).
Copying fails when the "auth=true" parameter is enabled in the mongo config. If you turn it off "#auth=true", then copying is successful.
In general, I did not figure out how to authorize a user when trying to copy a database and the "auth=true" parameter is enabled

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2015-10-13
Syomochkin @mak_sim

I think the answer is here . Follow the link for instructions on how to generate a key value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question