How to rename/clone the cosmos db colletion?

Nilesh Prajapati 21 Reputation points
2022-04-08T06:22:10.627+00:00

Hi Team,
Below is our nosql cosmos db-
191262-screenshot-2022-04-08-at-114648.png

Here,
We want to make copy/clone of collection - 'MenuItemDetailsV2', with new name i.e. 'MenuItemDetailsV2_backup'

Please suggest how we can do it.

Business use-case-
Take backup of existing collection and make clone of X collection with same name.

Looking for your expert advice,
Thank you

Regards,
Nilesh P

Tech lead, Mobiquity Solutions

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,710 questions
{count} votes

Accepted answer
  1. Sreeju Nair 12,456 Reputation points
    2022-04-08T07:01:24.207+00:00

    You have couple of options here. Let me give you a brief about the options one by one.

    1. Use Azure Cosmos DB Data Migration Tool.
      As per the documentation states The Azure Cosmos DB Data Migration tool is an open source solution that imports data to Azure Cosmos DB from a variety of sources, including Azure Cosmos DB collections. The tool is available as a graphical interface tool or as command-line tool.
    2. Use Azure Data Factory "Copy Activity" to copy data from and to to Azure Cosmos DB. Refer https://learn.microsoft.com/en-us/azure/data-factory/connector-azure-cosmos-db?tabs=data-factory
    3. I found a tool in github than can do the job. https://github.com/Microsoft/CosmicClone. You may refer the documentation in the github about how to use the tool.
    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Gillhofer Michael 26 Reputation points
    2022-10-20T11:37:57.413+00:00

    As of end of 2022, is there still no way to rename a collection without moving all of its content?

    5 people found this answer helpful.
    0 comments No comments

  2. Greg Gum 11 Reputation points
    2024-11-28T10:51:36.7533333+00:00

    Cosmos DB is a break from t-sql where renaming a table is trivial. A No-SQL database is more accurately called a DocumentDB, and so of course a container (collection) is a directory on a harddrive somewhere in the cloud. If you enable changing the name of the directory, you now have to be concerned about exclusive locks so someone else does not try to change at the same time. In other words, you are now back to a SQL Database solution. And what will happen to changes being made at the same time by processes which are expecting it to have a certain name?

    However, there is an easy way to achieve the same result in the data explorer. Go to "Settings" then "Partition Keys" and then click "Change". Enter the new name, use the same partition key, and click "Change" It will create the new container and move the data over to it. After it completes, you can the delete the old container.

    If you are keen to retain the original container name, then after deleting the old container, you can now move it a second time to a new container with the original name.

    See the docs here: https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/change-partition-key

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.