[SERVER-732] copyCollection command Created: 11/Mar/10  Updated: 30/Jan/19  Resolved: 22/Jan/19

Status: Closed
Project: Core Server
Component/s: Storage
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Namlook Assignee: Geert Bosch
Resolution: Won't Fix Votes: 88
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-1307 copy collection Closed
Related
is related to SERVER-15571 Make a command to copy a collection l... Backlog
Sprint: Storage NYC 2019-01-14, Storage NYC 2019-01-28
Participants:
Case:

 Description   

make a copy of a collection

{ copyCollection : "foo" <short collection name, not full namespace>
to : <short collection name>
fromdb : OPTIONAL
fromHost : OPTIONAL
query : OPTIONAL
snapshot : OPTIONAL
}



 Comments   
Comment by Brian Lane [ 22/Jan/19 ]

We have decided to close this issue as won't fix.

Due to security concerns, we feel it is better to use mongodump and mongorestore tools to transfer data between nodes. You can choose to run those tools on the same host running the mongod process if that fits with your security policy. There is also the db.cloneCollection() method, but this doesn't work when authorization is enabled on the from server.

Feel free to comment on this issue to provide additional feedback to us.

-Brian

Comment by David Schrooten [ 15/Nov/17 ]

It's ridiculous that this functionality is still not included in MongoDB 3.6. It's quite important when working with large collections and multiple databases on the same server. You could extend the cloneCollection functionality to allow connections to instances with auth enabled.

Comment by Timothee Cour [ 25/Jan/17 ]

Asked here https://groups.google.com/forum/#!searchin/mongodb-user/timothee$20cour|sort:relevance/mongodb-user/lSVXFPrtbaA/9fPuQNiLCQAJ
and was pointed to here; signed up to upvote this.
As said there, my workaround was:
```
db.profile.renameCollection('users.profile_temp')
db.cloneCollection('mongodb.example.net:27017', 'users.profile')
db.profile.renameCollection('users.profile_cloned')
db.profile_temp.renameCollection('users.profile')
```

Btw, @Namlook can we rename this issue as `cloneCollection + renaming` (more descriptive)

Comment by Albert Engelbrecht [ 03/Apr/14 ]

Also worthy to note that the workaround also is prone to type changes as well.

Comment by Anthony Fejes [ 27/Mar/14 ]

Signed up just to vote for this - it's a very basic operation that really should just be an extension to the copyCollection command, and William is absolutely right - the work around is very slow, when this should be a quick operation.

Comment by William Hidden [ 13/Jan/14 ]

While the workaround works it is much slower than copyCollection. Also there is a need to address authentication which is not provided in the proposed API.

Comment by Daryl Tucker [ 07/Sep/13 ]

Temporary solution/workaround:

db.<collection_name>.find().forEach(function(d){ db.getSiblingDB('<new_database>')['<collection_name>'].insert(d); });

Comment by Eliot Horowitz (Inactive) [ 19/Apr/11 ]

This will get done in vote order

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