Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
Delete item from CosmosDB

I'm trying to delete entries from Azure CosmosDB.

Documetation says:

/**
 * Delete item
 * Pass the id and partition key value to delete the item
 */
const { resource: result } = await container.item(id, category).delete();
console.log(`Deleted item with id: ${id}`);

My function to delete and items is:

// takes in an entry id to detete and deletes it with the documentation
async function findItemsToDelete(idToDelete){

    const category = config.partitionKey; // partitionKey is {kind: "Hash", paths: ["/requests"]} and I've also tried just "/requests"

    // the four lines below are correct
    const { endpoint, key, databaseId, containerId } = config;
    const client = new CosmosClient({ endpoint, key });
    const database = client.database(databaseId);
    const container = database.container(containerId);

     // query to return item with id (random code to make sure the item exists)- not important
     const querySpec = {
         query: `SELECT * FROM c WHERE c.id = "${idToDelete}"`
     };
     const { resources: items } = await container.items
         .query(querySpec)
         .fetchAll();

// below is the delete code from the documentation
    const { resource: result } = await container.item(idToDelete, category).delete();
    
    // random array holding the item that was just deleted- not important
    return items;
  }

When I try calling this, I get an error that says: Entity with the specified id does not exist in the system. Does anyone know how to properly implement this? I know the id is correct but I believe I may be doing something wrong with the partitionKey/Category part.

I saw in this post: Cannot delete item from CosmosDB that i may need the partition key value, but I dont know what that is or how to get it. Please let me know if you know what's going on!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!