Reputation: 106
Hello stackoverflow community. I am trying to organize soft delete solution for dynamodb.
If you have though on the same problem and find out any solution, please share in comment.
It involves thinking about: List items (isDeleted: false or 0), and use limit of results.
Upvotes: 3
Views: 4758
Reputation: 106
We need to create RANGE
index, for example Number
with any data (0/1).
In my case it is "isActive = 1"
for not deleted items.
Then we do query or scan with that IndexName.
In order to make item soft deleted, we need to remove attribute "isActive"
DynamoDB Scan and Query with Index
Official Best Practice: Take Advantage of Sparse Indexes - there is described our case.
In order to remove attribute use this example:
const params = {
TableName: this.TABLE,
Key: {
_id: id
},
UpdateExpression: 'REMOVE isActive',
ReturnValues: 'ALL_NEW'
}
return dynamodb.update(params).promise()
.then((data) => {
if (data) {
return data.Attributes
}
return null
})
Upvotes: 4