Search code examples
javascriptnode.jsazure-cosmosdb

Patch request to COSMOS DB: 404 not found


Updated: Solved by Sajeetharan's suggestion! Thanks.

I'm trying to implement the api to partially update cosmos db. I got 404 not found when I tested this patch request. I tested query in cosmo's db, it's working as expected. I don't know which part is wrong.


Solution

  • You should invoke the Patch on the container as how you have done fetchAll request.

    Here is a sample,

    const multipleOperations: PatchOperation[] = [
      {
        op: "add",
        path: "/aka",
        value: "MeFamily"
      },
      {
        op: "replace",
        path: "/lastName",
        value: "Jose"
      },
      {
        op: "remove",
        path: "/parents"
      },
      {
        op: "set",
        path: "/address/zip",
        value: 90211
      },
      {
        op: "incr",
        path: "/address/zip",
        value: 5
      }
    ];
    const { resource: patchSource2 } = await container.item(patchId!).patch(multipleOperations);