Python Boto3 DynamoDB - 如何解析地图值类型?

Python Boto3 DynamoDB - How to parse map value types?

我正在以这种格式将值存储在我的 dynamodb 数据库中 {"user_id":123456789,"user_xp_stats":{"user_level":15,"user_xp":12670}} 在我为特定用户的“xp_stats”请求 get_item 后,我得到一个这样的对象: { "M" : { "M" : { "user_level" : { "N" : "1" }, "user_xp" : { "N" : "8.1" } } }} 我应该如何解析它?

换句话说,我应该把它作为一个映射或存储“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?

仅凭这一个例子很难做出判断。如果您的项目通常有 user_leveluser_xp,我会将其保留为单独的属性。

这会为您提供更多选择,例如您可以稍后根据这些属性创建 Global Secondary Indices。正如您注意到的那样,它也更易于读写,然后是单个 map.