[SERVER-317] Copy a single collection from DB1 to DB2 Created: 25/Sep/09  Updated: 12/Jul/16  Resolved: 30/Sep/09

Status: Closed
Project: Core Server
Component/s: Tools
Affects Version/s: 1.0.0
Fix Version/s: 1.1.2

Type: New Feature Priority: Major - P3
Reporter: Oliver Eilhard Assignee: Michael Dirolf
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac OS X


Participants:

 Description   

With the current mongodump/mongorestore, it's not possible to copy just one collection from one database to another
(see this thread on mongodb-user: http://groups.google.com/group/mongodb-user/browse_thread/thread/daebd48eca33d3ee)

I expected to do something like this, but unfortunately mongorestore does

a) always use the original DB although I specified the target DB with the -d option (I heard the nightly builds behave different) and
b) always restores the complete DB instead of a single collection.

I thought I could copy over one collection to another DB with something like this:

pinocchio:~ oliver$ mongodump -d services -c suppliers -o tmp/dump
connected to: 127.0.0.1
DATABASE: services to tmp/dump/services
services.suppliers to tmp/dump/services/suppliers.bson
29603 objects

pinocchio:~ oliver$ mongorestore -d services_dev -c suppliers --dir
tmp/dump/
connected to: 127.0.0.1
tmp/dump/services/suppliers.bson
going into namespace [services.suppliers]
read 489874/11917784 bytes so far. (4%) 1028 objects
...
read 11605076/11917784 bytes so far. (97%) 28784 objects
29603 objects



 Comments   
Comment by Michael Dirolf [ 25/Sep/09 ]

this will work as you described it - as long as you only dump a single collection (or specify a path to a single collection's .bson file to restore) you should be fine.

note to restore to a different db you still need to be on a nightly build, not 1.0

Generated at Thu Feb 08 02:53:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.