Boto DynamoDB2条件put_item [英] Boto DynamoDB2 conditional put_item

查看:135
本文介绍了Boto DynamoDB2条件put_item的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让put_item在实际添加新项目之前检查是否有具有相同HashKey的项目.

I am trying to have put_item to check if there is item with the same HashKey before actually adding the new item.

根据boto DynamoDB2文档,可以使用条件放置"来实现.

According to boto DynamoDB2 document, it is possible to do it with "Conditional Put".

我尝试了以下命令,但是没有运气.

I tried following command but no luck.

connection.put_item('table',item={'locationId':'a1', 'timestamp': time.time()}, expected={'locationID':False})

错误消息如下.

boto.exception.JSONResponseError: JSONResponseError: 400 Bad Request
{u'Message': u'Expected null', u'__type': u'com.amazon.coral.service#SerializationException'}

有人对DynamoDBv2有条件认购权吗?

Does anyone have a conditional put with DynamoDBv2?

谢谢大家.

推荐答案

您需要像这样编写它才能使语法起作用.没有任何地方记录下来是非常糟糕的.我只是遇到了完全相同的问题,在浏览Java SDK文档时必须尝试50种不同的方法才能使其正常工作.请注意,如果要使用'Exists': True而不是False,则需要提供一个值.

You need to write it like this for the syntax to work. It's extremely bad that this isn't documented anywhere. I just had the exact same problem and had to try 50 different things while digging through the Java SDK documentation for it to work. Note that you need to give a value if you want to go with 'Exists': True instead of False.

connection.put_item(
    'table',
    item={
        'locationId':{'S': 'a1'},
        'timestamp': {'N': str(time.time())
    },
    expected={
        'locationID': {'Exists': False}
    }
    #expected={
    #    'locationID': {'Exists': True, 'Value': {'N': '0'}}
    #}
)

希望有帮助!

该问题帮助我使用了足以使其起作用的语法 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆