使用博托DynamoDB多值数据 [英] Multi-valued data in DynamoDB using boto

查看:221
本文介绍了使用博托DynamoDB多值数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

精练的文档和各种教程后,我想不出如何设置或更新一个发电机项目是一个多值的数据类型(数字或字符串集)的属性。我使用博托(boto.dynamodb2,要具体 - 不是boto.dynamodb)。

After scouring the documentation and various tutorials, I cannot figure out how to set or update an attribute on a dynamo Item that is a multi-valued data type (number or string set). I'm using boto (boto.dynamodb2, to be specific -- not boto.dynamodb).

尝试这样的事情(其中'身份证'是哈希键):

Trying something like this (where 'id' is the hash key):

Item(Table('test'), data={'id': '123', 'content': 'test', 'list': [1,2,3,4]}).save()

导致此错误:

TypeError: Unsupported type "<type 'list'>" for value "[1, 2, 3, 4]"

我觉得这一定有可能在boto.dynamodb2,但奇怪的是,我找不到人这样做任何的例子。 (每个人都只是设置编号或字符串的属性,而不是数量设置或字符串的属性集。)

I feel like this must be possible in boto.dynamodb2, but it's odd that I can't find any examples of people doing this. (Everyone is just setting number or string attributes, not number set or string set attributes.)

有关这个主题的任何见解,我怎么可能得到这个与博托工作将非常AP preciated!我猜我俯瞰简单的东西。谢谢!

Any insight on this topic and how I might get this to work with boto would be very much appreciated! I'm guessing I'm overlooking something simple. Thanks!

推荐答案

好了,我们可以算出这个对我们自己。上面我举的例子的问题是,我使用的是一个列表,而不是一组。一个多值属性的值必须是一组。

Okay, we were able to figure this out on our own. The problem with my example above is that I'm using a list instead of a set. The value of a multi-value attribute MUST be a set.

例如,此作品:

Item(Table('test'), data={'id': '123', 'content': 'test', 'list': set([1,2,3,4])}).save()

这篇关于使用博托DynamoDB多值数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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