2

我在Windows 7上本地安裝DynamoDB。 我的項目是一個Node.js(0.12.0),我使用aws-sdk。如何在本地使用GlobalSecondaryIndexes在DynamoDB上創建表?

版本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

回答

1

我解決了我的問題。

我加入了AttributeDefinitions的經度。

AttributeDefinitions: [{AttributeName: 'userId', AttributeType: 'S'}, {AttributeName: 'longitude', AttributeType: 'N'}] 
相關問題