Updating existing items with new properties in CosmosDB

2JK 241 Reputation points
2021-09-30T13:21:30.333+00:00

I have a container with a text field I need to pass to an API and get the results. I want to then store the result in the same document/item, so just add the new properties to the same item. How can I best do that without using Azure Function? I want it to run when a new document is inserted into the container.

So this:

{
   id: "1",
   name: "abcd",
   text:  "request",
} 

will be this:

{
   id: "1",
   name:  "abcd",
   text: "request",
   response: "response"  
} 

Where response is a property from the API response object.

I tried meddling with UDFs and Triggers but not much worked. Is there no way to do this without Azure Functions?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,336 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,459 questions
0 comments No comments
{count} votes

Accepted answer
  1. Saurabh Sharma 23,751 Reputation points Microsoft Employee
    2021-10-01T22:42:12.857+00:00

    Hi @2JK ,

    Thanks for using Microsoft Q&A !!
    No, I do not think there is a way to get it done without invoking Azure Functions from Cosmos DB triggers. You could try looking into Azure Cosmos DB Change Feed. Change Feed normally listens to an Azure Cosmos Db Container for any changes. You can then use Change Feed Processor library for listening the change feed to perform any specific actions. You can host the change feed processor in any platform that supports long running processes or task such as Azure WebJobs or an Asp.NET hosted service. I have never tried this option but you can check if this helps you achieve what you are looking for without using Azure Functions but the easiest solution is Azure Functions only.

    Thanks
    Saurabh

    ----------

    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful