1
votes

I have 2 databases, a prod and a test. I want to write a stored procedure to empty test, and populate it with items from prod. Prod isnt huge, ~2k items.

If this is better achieved without a stored procedure, im also open to that :)

Can anyone point me to any resources around this? I am currently using the bulk import base procedure, but I cant figure out how to access another db's items within that.

1
This requirement have many ways to achieve. You can try to use something like datafactory which will make everything be simple. Please have a look of my answer,.Cindy Pau
I would suggest looking at Cosmos DB's *changefeed" feature. As for a stored procedure, you'll run into issues if you have multiple partitions, as stored procedures are scoped to a single partition. Aside from that: this really isn't something that can be answered objectively, as there are several possible approaches.David Makogon

1 Answers

0
votes

1, Use Azure Datafactory. Create a pipeline and use copy activity to copy. Set your test database as the source and the prod database as the sink.

2, Use Azure Function, then use binding or just put the code in the body of function.

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2

3, Use CosmosDB Data migration tool.

This is the doc:

https://docs.microsoft.com/en-us/azure/cosmos-db/import-data

For example, If use Azure Datafactory to achieve your requirement, you can follow below steps:

First of all you need to create a datafactory on azure.

Step 1: Create pipeline:

enter image description here

Step 2: Create a copy activity:

enter image description here

Step 3: Click the copy activity, create the dataset:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Above is how to create source dataset, create sink dataset is similar.

Step 4: Then Just Click Debug:

enter image description here