question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I patch a large JSON document in Cosmos (something similar to T-SQL UPDATE) ?

See original GitHub issue

Is your feature request related to a problem? Please describe. I have a Cosmos database with hundreds of documents and each document is over 2 KB. We have added a new application feature and as a result of which there is a need to update a certain fragment in the JSON or add a new fragment to the JSON.

Scenario 1- Update

In the following example, I would like to update the city of all records from LDN to LONDON

{
 "firstname":"John",
 "lastname":"Doe",
 "city":"LDN"
}

Scenario 2 - Add new fields

In the following example, I would like to insert the country field to all records to GB and region to 'WEST EUROPE`

{
 "firstname":"John",
 "lastname":"Doe",
 "city":"LDN",
 "country":"GB",
 "region":"WEST EUROPE"
}

Describe the solution you’d like Something similar on the lines of T-SQL but relevant for JSON. E.g.

update Customers c where c.city="London" set "$.country="GB" , set "$.region="WEST EUROPE"

Describe alternatives you’ve considered I have had to write C# code on a case by case basis. In my code, I am having to deal with the JSON manipulation. This has become very burdensome when compared with how easy such a scenario would have been in the MSSQL world.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
stuartleekscommented, Feb 10, 2021

What is the ETA for this feature being publicly available?

2reactions
iamalexmangcommented, Sep 1, 2020

@ealsur, since #1616 is merged, do we now have patch support working? And if so… how does it work?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Partial document update - Azure Cosmos DB for NoSQL
The Partial document update operation is based on the JSON Patch RFC. Property names in paths need to escape the ~ and /...
Read more >
Modifying JSON data using JSON_MODIFY() in SQL Server
We use JSON_MODIFY() function to update the JSON string. It can update the following items: Update existing property value; Add a new element...
Read more >
JSON Patching in Cosmos DB
JSON Patch is a format that let you update JSON document partially. You can do more than updating a property. You can add,...
Read more >
Azure Cosmos DB SQL API UPDATE statement
The Cosmos DB SQL language only supports the Select statement. Partially updating a document isn't supported via the sql language or the SQL...
Read more >
Using Partial Update operations in Azure Cosmos DB
In a regular update operation, you need to send the whole JSON document to Cosmos DB. This can be silly if your data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found