Domanda

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

È stato utile?

Soluzione 2

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/

Altri suggerimenti

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

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top