我们可以只通过范围键删除dynamo db中的多条记录吗?
我正在尝试像这样的sql语句
{
"type": "is array",
"count": 30,
"summary": [
{
"DATE": "2017-08-01"
},
{
"DATE": "2017-08-02"
},
{
"DATE": "2017-08-03"
},
{
"DATE": "2017-08-04"
},
{
"DATE": "2017-08-05"
},
{
"DATE": "2017-08-06"
},
{
"DATE": "2017-08-07"
},
{
"DATE": "2017-08-08"
},
{
"DATE": "2017-08-09"
},
{
"DATE": "2017-08-10"
},
{
"DATE": "2017-08-11"
},
{
"DATE": "2017-08-12"
},
{
"DATE": "2017-08-13"
},
{
"DATE": "2017-08-14"
},
{
"DATE": "2017-08-15"
},
{
"DATE": "2017-08-16"
},
{
"DATE": "2017-08-17"
},
{
"DATE": "2017-08-18"
},
{
"DATE": "2017-08-19"
},
{
"DATE": "2017-08-20"
},
{
"DATE": "2017-08-21"
},
{
"DATE": "2017-08-22"
},
{
"DATE": "2017-08-23"
},
{
"DATE": "2017-08-24"
},
{
"DATE": "2017-08-25"
},
{
"DATE": "2017-08-26"
},
{
"DATE": "2017-08-27"
},
{
"DATE": "2017-08-28"
},
{
"DATE": "2017-08-29"
},
{
"DATE": "2017-08-30"
}
]
}
所以这里员工姓名delete from employee where employee_name='gopal';
的记录应该被删除
我们可以在dynamo db中实现这样的sql查询吗?
答案 0 :(得分:2)
您必须执行BatchWriteItem才能删除项目。 From the documentation:
BatchWriteItem执行put和delete
答案 1 :(得分:0)
基于API,DynamoDB没有批量删除。
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html
您需要查询该项目并使用其分区键删除。
我建议看看ODM,
https://github.com/clarkie/dynogels
使操作更简单。
查看要删除的样本调用
Pulse()
答案 2 :(得分:0)
@Kannaiyan感谢您的评论......
我找到了带有java http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/JavaDocumentAPICRUDExample.html
的dynamoDB的解决方案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);
使用键,值对获取记录并将其存储在" withValueMap(new ValueMap()"这有助于我。
感谢。
答案 3 :(得分:0)
请选中此查询,它正在处理多个数据
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");
});
});
});
答案 4 :(得分:-2)
希望这可能有所帮助:
import boto.dynamodb
import boto.dynamodb.condition as condition
修改以下值以设置您的AWS区域和访问密钥:
将此设置为AWS区域,例如' us-west-2',' us-east-1'等
REGION = 'us-east-1'
复制下面的AWS访问密钥值:
AWS_ACCESS_KEY = 'your_access_key'
复制下面的AWS秘密访问密钥值:
AWS_SECRET_ACCESS_KEY = 'your_secret_access_key'
在下面设置AWS云温度计表的名称:
TABLE_NAME = 'Temperatures'
设置为要删除的Id值的名称。具有此ID的所有行都将被删除!
ID_TO_DELETE = 'id_value_to_delete'
连接到桌面。 `
conn = boto.dynamodb.connect_to_region(REGION,` aws_access_key_id=AWS_ACCESS_KEY, aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
temperatures = conn.get_table(TABLE_NAME)
打印警告
print 'About to delete all rows with Id {0} from table {1} in {2}.'.format(ID_TO_DELETE, TABLE_NAME, REGION)
print 'Are you sure? (y/n)'
response = raw_input().upper()
if response != 'Y' and response != 'YES':
print 'OK, not deleting anything!'
quit()
扫描表格并删除与提供的ID匹配的所有项目
print 'Deleting rows...'
count = 0
for row in temperatures.scan(scan_filter={'Id': condition.EQ(ID_TO_DELETE)}):
count += 1
row.delete()
打印'已删除{0}行。' .format(count)