我正在尝试DynamoDB
使用的数据格式创建一个新表MongoDB
。我知道如何创建基本表和更新数据,但是,对于嵌套JSON
体,由于这是我的新手,因此我无法创建KeySchema。
我的JSON示例:
{
'Name':"fresco"
'Tags':{
'Genre':'Jazz'
'Albums':['aa','bb''cc']}
'Year:'2009
}
我正在使用boto3,并且我知道如何与AWS连接,我只需要有关此JSON主体的keychema的帮助。另外,我已经从AWS文档中阅读了Map属性,但没有实现。
我的代码:
import boto3
dynamodb =boto3.resource('dynamodb')
table = dynamodb.create_table(
TableName = 'newTable'
KeySchema = [
{
'AttributeName': 'Name',
'KeyType': 'Hash'
},
{
'AttributeName': 'Tags',
'KeyType': 'Hash'
},
{
'AttributeName': 'Year',
'KeyType': 'Hash'
}
],
AttributeDefinitions=[
{
'AttributeName': 'Name',
'AttributeType': 'S'
},
{
'AttributeName': 'Tags',
'AttributeType': #dont know what to put in here.
},
{
'AttributeName': 'Year',
'AttributeType': 'N'
},
],
ProvisionedThroughput ={
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 5
}
)
在DynamoDB中,您只能具有一个分区键或一个分区键+一个排序键。而且,您对密钥的长度也有限制-因此标签可能不是最合适的。最好阅读开发人员文档。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句