Home > Blockchain >  Updating all the items in Azure Cosmos DB using SQL Query
Updating all the items in Azure Cosmos DB using SQL Query

Time:03-02

I'm currently working on Azure Cosmos DB and I'm trying to update a property for all the items present in the container using SQL Query, but I'm getting an error which says "Syntax error, incorrect syntax near 'UPDATE'.". Can anyone help me with this, I want to know whether I'm doing it wrong or the Azure Cosmos SQL doesn't support "Update" function. The SQL query which I've used is:

UPDATE c
set ttl = 10

Thanks in advance!!!

CodePudding user response:

No Cosmos SQL API does not have the support Update yet.

You need to use the SDK inorder to perform Bulk Upserts, if you are using .NET you could perform Bulk operations as mentioned here.

public async Task BulkUpsert(List<SomeItem> items)
{
    var concurrentTasks = new List<Task>();

    foreach (SomeItem item in items)
    {
        concurrentTasks.Add(container.UpsertItemAsync(item, new PartitionKey(item.PartitionKeyField)));
    }

    await Task.WhenAll(concurrentTasks);
}
  • Related