I have a collection named tracks in a db named socialmedia in my mongo. How can i copy this collection to another mongodb in my network ?
Update: there is only one mongodb instance
I have a collection named tracks in a db named socialmedia in my mongo. How can i copy this collection to another mongodb in my network ?
Update: there is only one mongodb instance
Export your collection to file, copy the file to the other machine and import it on your other machine.
Export from commandline to file:
mongoexport -d socialmedia -c tracs -o filename.json
Import a file(in the same folder) from commandline :
mongoimport -d socialmedia -c tracs --file filename.json
copyTo
should only work within one MongoDB instance, right? This question makes not clear if two instances are used.
Use cloneCollection
http://docs.mongodb.org/manual/reference/command/cloneCollection/
On the target server, run
{ cloneCollection: "databaseName.socialmedia", from: "mongodb.example.net:27017" }
If you wanted to do this on the same server:
db.socialmedia.copyTo(newNameOfSocialmedia)
http://docs.mongodb.org/manual/reference/method/db.collection.copyTo/
Use mongo import and export. Explanation you can find here
mongoimport --db project_test_db --collection users --out export/users.json
mongoexport --db project_test_db --collection users --sort '{fieldName: 1}' --limit 100 --skip 10 --out export/users.json