[SERVER-15571] Make a command to copy a collection locally, then have db.collection.copyTo use it. Created: 08/Oct/14  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Usability
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Rod Adams Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
related to SERVER-732 copyCollection command Closed
is related to SERVER-17478 Remove or modify copyTo() shell helper Closed
Assigned Teams:
Query Execution
Participants:

 Description   

Right now, db.collection.copyTo is implemented in as a shell helper which runs a server side javascript method. This serverside feature is nice, since it eliminates network hops to and from the client for each document. However, this implementation suffers the problem using eval(), which in any situation with auth enabled, requires permissions that we actively advise not giving anybody.

Instead, what if there was a proper command on the server for this? We have several options for copying from another host, so it would seem to fit in. Once it exists, copyTo could be reimplemented to call the command, without the need for eval.



 Comments   
Comment by Sara Golemon [ 02/Jul/18 ]

Additionally, the {renameCollection:...} command (which aggregate $out uses internally to make the collection creation appear atomic, would precisely serve the purpose rod.adams described including being able to work across databases (which neither the agg pipeline nor collection.copyTo() currently support.

There is still possibly a use case for a copyCollection which works across databases, or possibly: {renameCollection: ..., dropSource: false} if one were to piggy-back on the existing command.  Or perhaps optimizing the case in cloneCollection where the from server is ourselves.

Comment by Asya Kamsky [ 23/Mar/17 ]

Within the same DB (which is all copyTo can do, I believe) we have aggregation with "$out" stage.

Comment by Rod Adams [ 15/Mar/16 ]

I don't believe it does. The case I'm talking about is more often someone wanting to move a collection from one database to another, within the same server. I could see cloneCollection work, if it was allowed to rename the collection, and had a "local" backdoor which could be made much faster.

Comment by Adam Midvidy [ 07/Mar/16 ]

Does cloneCollection (https://docs.mongodb.org/manual/reference/command/cloneCollection/) serve your use case?

Generated at Thu Feb 08 03:38:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.