[DOCS-1698] cloneCollection always preserves db name in the destination DB Created: 12/Jul/13  Updated: 30/Oct/23  Resolved: 15/Jul/13

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Bug Priority: Minor - P4
Reporter: Nelson Elhage Assignee: Sam Kleinman (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 10 years, 31 weeks, 2 days ago

 Description   

The documentation for cloneCollection documents that it "creates a collection on the current database with the same name as the origin collection.": http://docs.mongodb.org/manual/reference/command/cloneCollection/

However, testing and source inspection reveal that it always copies to the database of the same name as the source database, e.g.:

[nelhage@anarchique:/tmp/mongo]$ mongo --port 9001
MongoDB shell version: 2.4.3
connecting to: 127.0.0.1:9001/test
> use testdb
switched to db testdb
> db.runCommand({cloneCollection: "nelhage.mydb", from: "localhost:9000"})
{ "ok" : 1 }
> db.mydb.find()
> db.getSiblingDB('nelhage').mydb.find()
{ "_id" : ObjectId("51df57ffacab3e1ad799d62e"), "i" : 6 }



 Comments   
Comment by auto [ 15/Jul/13 ]

Author:

{u'username': u'tychoish', u'name': u'Sam Kleinman', u'email': u'samk@10gen.com'}

Message: DOCS-1698: revise clone collection example
Branch: master
https://github.com/mongodb/docs/commit/843b8f271540e06335cda4026b67e32b03b8890c

Comment by J Rassi [ 12/Jul/13 ]

We'll keep the command's default behavior as is; changing it would introduce a significant backwards-breaking change without very much benefit (also, the command's help method has always been correct on this point, but those are admittedly rarely used).

Do feel free to open a separate SERVER ticket for your proposal, perhaps as a feature request for an new option to cloneCollection command. It's clear that the behavior you desire would make it easier to create quick backups of individual collections.

Comment by Nelson Elhage [ 12/Jul/13 ]

Fixing the docs would definitely be preferable to keeping them wrong, but fwiw I found this because I wanted the documented behavior, so my 2ยข would be to vote for fixing the code instead of the docs (from reading the code, it doesn't look like it'd be fundamentally hard for any reason I can see – the internal copy API already takes two "ns" arguments). But it's your call, of course.

Comment by J Rassi [ 12/Jul/13 ]

Confirmed as a documentation bug, moving to DOCS project.

Generated at Thu Feb 08 07:41:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.