Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

95
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda