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

855
Visualizações
DynamoDb delete non-existent item does not fail, why?

I am deleting a non-existing record from the dynamodb table using dynamoDbMapper.delete(object) which uses default DynamoDBDeleteExpression

I was expecting some sort of exception to arise since the record is absent from the DB but it does nothing. It does not even have a return type which could tell if the delete was successful or failure. Is there a way to add a delete expression or something which will make my delete throw an exception if the item is absent from the db?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

It is by design:

Unless you specify conditions, the DeleteItem is an idempotent operation; running it multiple times on the same item or attribute does not result in an error response.

FROM: https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html

over 4 years ago · Santiago Trujillo Relatório

0

It's possible to utilize ReturnValues to determine if delete did anything or not. If ReturnValues.Attributes is empty, it means delete didn't find a record to delete, and you can throw an error in this case. Example in JavaScript:

async function deleteWithThrowIfNotExists() {
  const dynamo = new AWS.DynamoDB.DocumentClient();
  const parameters = {
    Key: {
      user: 'john'
    },
    ReturnValues: 'ALL_OLD',
    TableName: 'users'
  };
  const response = await dynamo.delete(parameters).promise();
  if (!response.Attributes) {
    throw new Error('Cannot delete item that does not exist')
  }
}
over 4 years ago · Santiago Trujillo Relatório

0

You can first load the item, and if item doesn't exists you can throw exception otherwise delete it.

over 4 years ago · Santiago Trujillo Relatório
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