gpt4 book ai didi

javascript - 如何在本地使用 GlobalSecondaryIndexes 在 DynamoDB 上创建表?

转载 作者:行者123 更新时间:2023-11-30 00:31:15 24 4
gpt4 key购买 nike

我在 Windows 7 上本地安装 DynamoDB。我的项目是 Node.js(0.12.0),我使用 aws-sdk。

DynamoDB 版本:2012-08-10

这项工作 ->

dynamodb.createTable({
TableName: 'Users',
AttributeDefinitions: [{AttributeName: 'userId', AttributeType: 'S'}],
KeySchema: [{AttributeName: 'userId', KeyType: 'HASH'}],
ProvisionedThroughput: {
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 5
}
}, function () {
...
});

这行不通 ->

dynamodb.createTable({
TableName: 'Users',
AttributeDefinitions: [{AttributeName: 'userId', AttributeType: 'S'}],
KeySchema: [{AttributeName: 'userId', KeyType: 'HASH'}],
ProvisionedThroughput: {
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 5
},
GlobalSecondaryIndexes: [
{
IndexName: 'longitudeUserIndex',
KeySchema: [
{
AttributeName: 'userId',
KeyType: 'HASH'
},
{
AttributeName: 'longitude',
KeyType: 'RANGE'
}
],
Projection: {
NonKeyAttributes: [
],
ProjectionType: 'KEYS_ONLY'
},
ProvisionedThroughput: {
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 5
}
}
]
}, function () {
...
});

DynamoDB Javascript 文档:http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#createTable-property

最佳答案

我解决了我的问题。

我在 AttributeDefinitions 中添加了经度。

AttributeDefinitions: [{AttributeName: 'userId', AttributeType: 'S'}, {AttributeName: 'longitude', AttributeType: 'N'}]

关于javascript - 如何在本地使用 GlobalSecondaryIndexes 在 DynamoDB 上创建表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29402503/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com