Using ADF is it possible to update id column in cosmos using upsert in sink. It is creating new document instead of updating the old document.

Chenthil Kumar 21 Reputation points Microsoft Employee
2022-07-21T11:26:27.12+00:00

I have already inserted millions of records using adf copy step into cosmos from azure sql.

Source data
pkey = 123
id = 27

In cosmos the same document is created
pkey: 123
id :27

Now i want to update the id to a different value based on pkey.
pkey: 123
id: guid()

Since cosmos doesn't provide the key column in the sink it is creating a new record instead of update the old. Any solutions.

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,434 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,463 questions
{count} votes

Accepted answer
  1. ShaikMaheer-MSFT 37,661 Reputation points Microsoft Employee
    2022-07-27T10:52:42.213+00:00

    Hi @Anonymous ,

    I had discussion with PG team also reproduced my end. Below are the complete details.

    id field in cosmos db item will going to act as Key column to perform update or delete or upsert. Hence You cannot update id field of document in cosmos db from dataflow.

    Please note, while you want to perform update or delete actions then mentioning partition Key is mandatory. Because based on that partition key service to go and search of id field value and if matching found then service will perform update or delete accordingly.

    In below screenshots example, my source data id will get mapped with Sink data id (cosmos Db document id) and then if matching found then update will happen if not insert will happen. Please note, category is partition key of my collection in cosmos DB.
    225291-image.png

    Hope this helps. Please let us know if any further queries.

    -----------

    Please consider hitting Accept Answer button. Accepted answers help community as well.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. manikanta reddy 0 Reputation points
    2024-03-06T05:34:11.66+00:00

    I tried the same thing but it is not updating can u pls suggest how to update view count column under the array in cosmos db container

    0 comments No comments