[英]Python Boto3 DynamoDB - How to parse map value types?
I am storing values in my dynamodb database in this format {"user_id":123456789,"user_xp_stats":{"user_level":15,"user_xp":12670}}
After I request a get_item for specific user's "xp_stats" I get a object like this: { "M": { "M": { "user_level": { "N": "1" }, "user_xp": { "N": "8.1" } } }}
How should I parse it?我以这种格式将值存储在我的 dynamodb 数据库中
{"user_id":123456789,"user_xp_stats":{"user_level":15,"user_xp":12670}}
在我为特定用户的“xp_stats”请求 get_item 后,我得到一个object 像这样: { "M": { "M": { "user_level": { "N": "1" }, "user_xp": { "N": "8.1" } } }}
我应该如何解析它?
In other words, should I have it as a map or store "user_level" and "user_xp" each separately as a single value?换句话说,我应该将它作为 map 还是将“user_level”和“user_xp”分别存储为单个值?
In other words, should I have it as a map or store "user_level" and "user_xp" each separately as a single value?
换句话说,我应该将它作为 map 还是将“user_level”和“user_xp”分别存储为单个值?
Its very difficult to make a call based on this one single example.基于这个单一的例子打电话是非常困难的。 If your items will usually have
user_level
and user_xp
, I would keep it as separate attributes.如果您的项目通常具有
user_level
和user_xp
,我会将其保留为单独的属性。
This gives your more options later on, eg you can create Global Secondary Indices later on based on these attributes.这为您以后提供了更多选择,例如您可以在以后基于这些属性创建全局二级索引。 Its also easier to read and write as you noticed then a single
map
.正如您注意到的那样,它也更容易读写,然后是单个
map
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.