Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add support for partial updates to document #448

Open
Szeraax opened this issue Nov 2, 2021 · 5 comments
Open

Feature request: Add support for partial updates to document #448

Szeraax opened this issue Nov 2, 2021 · 5 comments
Labels
enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community.

Comments

@Szeraax
Copy link

Szeraax commented Nov 2, 2021

Announced today, Cosmos has partial update support: https://devblogs.microsoft.com/cosmosdb/partial-document-update-ga/

@PlagueHO PlagueHO added enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community. labels Nov 2, 2021
@PlagueHO
Copy link
Owner

PlagueHO commented Nov 2, 2021

Hi @Szeraax - I just saw that too. I'm hoping the REST API's will be updated with this feature as well: https://docs.microsoft.com/en-us/rest/api/cosmos-db/

@Szeraax
Copy link
Author

Szeraax commented Nov 3, 2021

Closing for now at least.

@Szeraax Szeraax closed this as completed Nov 3, 2021
@Szeraax
Copy link
Author

Szeraax commented Sep 22, 2022

Hey @PlagueHO, am I reading this right that we now have PATCH capability in the API?

https://learn.microsoft.com/en-us/rest/api/cosmos-db/patch-a-document

@Szeraax Szeraax reopened this Sep 22, 2022
@Szeraax
Copy link
Author

Szeraax commented Sep 22, 2022

Looks like it is supported now and it requires that you use the Patch method with an array of operations. I think the best way to go about implementing this will be to add a PatchOperation type in our module class and then add a Update-CosmosDbDocument cmdlet. Update-CosmosDbDocument would have an optional PartitionKey string param, an optional conditional filter (probably just use -Filter for the param name), and would require an array of the [PatchOperation] objects.

Here is the other document that is helpful to look at: https://learn.microsoft.com/en-us/azure/cosmos-db/partial-document-update

Any guidance on my approach? Cool if I take a first pass at a PR or would you like me to do this in a different way?

@Szeraax
Copy link
Author

Szeraax commented Sep 22, 2022

Regarding the PatchOperation type, I'd need some help creating that class, since I'm a c# noob at best.

I guess a start would be:

    public class PatchOperation {
        public System.String op { get; set; }
        public System.String path { get; set; }
        public System.Object value { get; set; }
    }

But we'd need to restrict the op to one of the supported operations like add, remove, set, etc. Not sure how to set a validation set in c#. The path would be a string and that's no problem. But the value would need to be any object type that can convert to json (string, int, float, etc.). Dunno how to appropriately do that in the strongly typed world of c#.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community.
Projects
None yet
Development

No branches or pull requests

2 participants