I am trying to copy a MongoDB collection from one database to another database on the same server.
from pymongo import MongoClient
client = MongoClient()
client.db1.coll1.insert({'content':'hello world'})
I would like to copy db1.coll
to db2.coll2
on the same server.
I tried to follow the "copy and move" approach described in How to copy a collection from one database to another in MongoDB but this doesn't work in pymongo.
In particular, the copy step
client.db1.coll1.aggregate([{'$out':'coll2'}])
works but then I get an error when trying to perform the move:
>>> client.admin.command({'renameCollection':'db1.coll2', 'to':'db2.coll2'})
OperationFailure: no such command: 'to', bad cmd: '{ to: "db2.coll2", renameCollection: "db1.coll2" }