I was trying to use batchDelete in our app, get the result (which are the deleted Items) and process other things regarding those deleted Items.
In the docs, it says:
Returns an async iterable of items that have been deleted (deleted items are yielded when the delete has been accepted by DynamoDB).
Basically, I have a wrapper function in a service to do that. Following the code:
async batchDelete<T>(
Model: new () => T,
items: Array<DocumentClient.ItemCollectionKeyAttributeMap>,
): Promise<T[]> {
const itemsToDelete = items.map((item) => Object.assign(new Model(), item));
const deleteResult = this.mapper.batchDelete(itemsToDelete);
const deletedItems: Array<T> = [];
for await (const deletedItem of deleteResult) {
deletedItems.push(deletedItem);
}
return deletedItems;
}
}
In our DynamoDB, we have
Primary partition key | projectId (String)
Primary sort key | entityId (String)
If we pass an existing entityId but a wrong projectId, the batchDelete does not delete the Item, but it does returns actually the given argument.
I mean, if we pass to the function above the right Model class and [{ projectId: 'wrong-project-id', entityId: as existing entityId }], batchDelete is returning [{ projectId: 'wrong-project-id', entityId: as existing entityId }] event if the Item has not been deleted
Could someone check if we are doing something wrong, or is there a bug in this function?