I am using DynamoDB mapper for deleting an item but have to make sure it exists before deleting it?
So I'm currently doing
public void delete(final String hashKey, final Long rangeKey) {
final Object obj = mapper.load(Object.class, hashKey, rangeKey);
if (obj != null) {
mapper.delete(obj);
}
}
If there a way to delete an item without loading it first? I want it to silently return if the item was not found
With the DynamoDB API, you use the DeleteItem action to delete data from a table, one item at a time. You must specify the item's primary key values. In addition to DeleteItem , Amazon DynamoDB supports a BatchWriteItem action for deleting multiple items at the same time.
The DynamoDBMapper class is the entry point to Amazon DynamoDB. It provides access to a DynamoDB endpoint and enables you to access your data in various tables. It also enables you to perform various create, read, update, and delete (CRUD) operations on items, and run queries and scans against tables.
AWS DynamoDB Mapper query by GSI returns null for all non-key attributes.
Yes, you can!
Simply create an object with the ID you want to delete and pass it as an object to the delete method:
...
MyObject object = new MyObject();
object.setHashKey(hashKey);
object.setRangeKey(rangeKey);
mapper.delete(object);
....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With