I am attempting to use pymongo to clone a collection from a remote mongo instance, from the documentation cloning a collection requires the cloneCollection
command,
{ cloneCollection: "<collection>", from: "<hostname>", query: { <query> } }
and to run this command in pymongo I need to specify the additional parameters of the command as kwargs like this:
db.command("cloneCollection","db_name.collection_name", from = "localhost:27017")
But since from
is a reserved keyword in python I cannot use it as a keyword.
An alternative is to pass the command as a python dict like this:
db.command({"cloneCollection":"db_name.collection_name", "from":"localhost:27017"})
However in this case the order is not preserved, and I get this error
pymongo.errors.OperationFailure: command {'from': 'localhost:27017', 'cloneCollection': 'db_name.collection_name'} failed: no such cmd: from