Azure Cosmos DB: Clone collection to another database Azure Cosmos DB: Clone collection to another database azure azure

Azure Cosmos DB: Clone collection to another database


You can use data Migration tool suggested by Microsoft to do the same.

There is no way to take a backup and import cosmosdb.

EDIT:

With the new Cosmic Clone tool, you can take a clone/backup with data/stored procedures/triggers/udf, etc. Read my blog on the same.


I already tried to use Azure Data factory, but it looks like that there is no support for the Mongo API so far.

Actually, Cosmos DB Mongo API and SQL API are all belong to Azure Cosmos DB service.So , you still can create cosmos db linked service and dataset in the azure data factory for your database.

enter image description here

Then you could create copy activity to import data from one collection to another collection.

enter image description here

If you want to make it as an automation task, I suggest using following 2 ways to run the copy activity.

1.Azure Time Trigger Function.

2.Web job which is run in the background of Azure Web App.

Hope it helps you.Any concern, please feel free to let me know.


I used mongodump and mongorestore to copy my database (with mongodb version 4.0.9 installed). From the windows command line I ran the following commands from my mongodb bin directory (c:\Program Files\MongoDB\Server\4.0\bin in my case).

This will copy all the collections, including indexes, in the DB to the specified /out directory as .json files.

mongodump.exe /uri:URI /out:A_DIRECTORY_TO_DUMP_TO

I then ran the following command to take everything in the /out directory and write it to the target DB:

mongorestore.exe /uri:URI /dir:DIRECTORY_TO_RESTORE_FROM

NOTE: Before importing I also had to increase the throughput for the collection, otherwise I ran into rate limiting errors. If you've set throughput at the database level this may need to be changed.