I want to copy a database to another name into the same server with
pymongo. The mongodb documentation says:
> db.copyDatabase(<from_dbname>, <to_dbname>, <from_host>);
but there's no such method on pymongo (no Connection.copy_database).
So I tried with the `command` method without success :
>>> con = pymongo.Connection()
>>> con.test.command({'copydb':True, 'fromdb': 'test', 'todb': 'test2'})
<class 'pymongo.errors.OperationFailure'>: command {'fromdb': 'test',
'todb': 'test2', 'copydb': True} failed: no such cmd
>>> con.test.command({'copydb':True})
<class 'pymongo.errors.OperationFailure'>: command {'copydb': True}
failed: access denied
Any ideas ?
N.
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
> use admin
> db.runCommand({'copydb':1, 'fromdb': 'test', 'todb': 'test2'})
but when I run the same command with pymongo, I doesn't work:
>>> import pymongo
>>>> con = pymongo.Connection()
>>> con.admin.command({'copydb':1, 'fromdb': 'test', 'todb': 'test2'})
<class 'pymongo.errors.OperationFailure'>: command {'fromdb': 'test',
'todb': 'test2', 'copydb': 1} failed: no such cmd
What append ?
# pymongo 1.4
# mongodb 1.3.2
>>> from pymongo.son import SON
>>> con.admin.command(SON(copydb=1, fromdb='test', todb='test2'))
<class 'pymongo.errors.OperationFailure'>: command SON([('fromdb',
'test'), ('todb', 'test2'), ('copydb', 1)]) failed: no such cmd
I also tried :
>>> con.admin.command(SON(copydb=1, fromdb='test', todb='test2'))
<class 'pymongo.errors.OperationFailure'>: command SON([('fromdb',
'test'), ('todb', 'test2'), ('copydb', 1)]) failed: no such cmd
Which is weird as arguments are ordered...
Anyway, after digging, I tried :
>>> con.admin.command(SON([("copydb", 1), ("fromdb", 'test'), ("todb", 'test2')]))
{u'ok': 1.0}
Thanks !