I'm trying to copy my db for testing purposes. I'm using the docs for that, but it still fails:
from pymongo import MongoClient
client = MongoClient(username='root', password='pass')
client.admin.command('copydb', fromdb='src', todb='dst')
OperationFailure: no such command: 'copydb', full error: {'ok': 0.0, 'errmsg': "no such command: 'copydb'", 'code': 59, 'codeName': 'CommandNotFound'}
When trying another command, from another section of the doc, it worked:
from pymongo import MongoClient
client = MongoClient(username='root', password='pass')
db = client.src
db.admin.command('copydb', fromdb='src', todb='dst')
The objects used here are different, but this is what the docs say... I still tried using the db
object for the copydb
- and failed again:
from pymongo import MongoClient
client = MongoClient(username='root', password='pass')
db = client.src
db.admin.command('buildinfo')
TypeError: 'Collection' object is not callable. If you meant to call the 'command' method on a 'Collection' object it is failing because no such method exists.
which means I use a bad object (makes sense, but I don't get how to make it work)
pymongo.version: '3.11.0'
mongodb version: 4.4.1 (running on docker)