Mittenchops
Mittenchops

Reputation: 19724

How to execute the mongo cloneCollection command to copy a collection to a remote server

I'd like to copy a collection from one database to an instance on another server. From other stackoverflow questions, I understand the correct way to do that is with this command:

{ cloneCollection: "<collection>", from: "<hostname>", query: { <query> } }

via http://docs.mongodb.org/manual/reference/command/cloneCollection/

However, I don't understand where do I enter this command? It isn't accepted as...

$ mongod { cloneCollection: "remote", from: "ec2-whatever-amazon.com"}

How do I copy a remote collection at db.remote.collname to db.local.collname using this cloneCollection syntax via command line?

Upvotes: 4

Views: 2432

Answers (1)

Bobby Wallace
Bobby Wallace

Reputation: 203

MongoDB database commands are run using db.runCommand() from the mongo shell. Refer to http://docs.mongodb.org/manual/tutorial/use-database-commands/.

Try something like this (using another database command for simplicity):

$ mongo
 > db.runCommand({ isMaster: 1})
 {
    "ismaster" : true,
    "maxBsonObjectSize" : 16777216,
    "localTime" : ISODate("2014-02-18T22:30:04.417Z"),
    "ok" : 1
 }
 > 

Upvotes: 5

Related Questions