How can I use mongodump
to move a single collection from one database to another?
How should I use the command and its options?
Here is an example of how you can export a single collection with mongodump.exe
on Windows 10:
"D:\Program Files\MongoDB\Server\4.0\bin\mongodump.exe" -h localhost --port 27017 -d meteor --collection users -o meteor_users
The exported collection is users
, the database is meteor
, the host localhost
, the port is 27017
.
The output will be stored in directory meteor_users
.
Restoring should use a command like this one:
"D:\Program Files\MongoDB\Server\4.0\bin\mongorestore.exe" -d meteor -c users users.bson