Existing Cosmos DB documents need to be altered/updated with a new property & also existing documents of other collections need to be updated with the same new property along with its value.
Is there any recommended way or tool available to update existing documents on Cosmos DB, or is writing the custom c# application/PowerShell script using Cosmos DB SDK is the only option?
Example:
Existing user
document
{
id:[email protected],
name: "abc",
country: "xyz"
}
Updated user
document
{
id:[email protected],
name: "abc",
country: "xyz",
guid:"4334fdfsfewr" //new field
}
Existing order
document of the user
{
id:[email protected],
user: "[email protected]",
date: "09/28/2020",
amt: "$45"
}
Updated order
document of the user
{
id:[email protected],
user: "[email protected]",
userid: "4334fdfsfewr", // new field but with same value as in user model
date: "09/28/2020",
amt: "$45"
}
Upsert is an outbound action to either update or create a new record in Microsoft Azure Cosmos DB collection. This operation can be performed either in bulk or a single record by specifying Object/Record ID(s) and Partition Key.
You can only set it when you create a new container. If you do need to change a partition key, you need to create a new container and migrate your data to that one.
If you are trying to update the ID "108-406-004" to add a new property, you can use a copy activity with the option "Write behaviour" as "Upsert". Using this option will automatically add the new property to the record in Cosmos DB.
I'd probably go with:
[UPDATE] whatever type of script you feel best with: PS, C#, Azure Functions... now, what do you mean they need to be altered with the new property "on the same time"? i'm not sure that's possible in any way. if you want such an effect then i guess your best bet is:
its your choice how would you change other collections (orders): using changeFeed & Azure Functions from old or new users container.
PS. Yes, whatever flow i'd go with, it would still be Azure Functions with Cosmos DB trigger.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With