can we delete multiple records in dynamo db only through range key?
I\'m trying to do like this sql statement
delete from employee where emplo
Based on the API, there is no Batch Delete for DynamoDB.
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html
You need to query the item and delete with their partition key.
I would recommend looking at ODM,
https://github.com/clarkie/dynogels
to make the operations simpler.
Check out the sample calls for deletion,
Account.destroy('foo@example.com', function (err) {
console.log('account deleted');
});
// Destroy model using hash and range key
BlogPost.destroy('foo@example.com', 'Hello World!', function (err) {
console.log('post deleted')
});
BlogPost.destroy({email: 'foo@example.com', title: 'Another Post'}, function (err) {
console.log('another post deleted')
});
You would have to do a BatchWriteItem to delete your items. From the documentation:
BatchWriteItem performs put and delete
@Kannaiyan thanks for your comments....
i found the solution with dynamoDB with java http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/JavaDocumentAPICRUDExample.html
DeleteItemSpec deleteItemSpec = new DeleteItemSpec().withPrimaryKey("Id", 120)
.withConditionExpression("#ip = :val").withNameMap(new NameMap().with("#ip", "InPublication"))
.**withValueMap(new ValueMap()**.withBoolean(":val", false)).withReturnValues(ReturnValue.ALL_OLD);
fetching the records with key, value pair and storing it in "withValueMap(new ValueMap()" and this helps me.
Thanks.
Please Check This query it's working with multiple data
const params = {TableName: "test"};
docClient.scan(params, (error, result) => {
if (error) { console.log(error,"error scan"); }
result.Items.forEach(function(item) {
docClient.delete({Key:{mainID: item.id},TableName:"test"}, (error) => {
if (error) {
console.log("Delete fail");
}
console.log("Delete Success");
});
});
});