Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

93
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda