zukini
zukini

Reputation: 51

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.

Upvotes: 2

Views: 627

Answers (2)

BabyishTank
BabyishTank

Reputation: 1482

Azure have confusing error message for this.

  1. Check you are operating on the right container
  2. Check partition key is correct
  3. If you add adding new field, don't forget the '/' in "/newfield"

Upvotes: 0

Sajeetharan
Sajeetharan

Reputation: 222712

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);

Upvotes: 1

Related Questions