我正在使用Node.js
var AWS = require('aws-sdk');
AWS.config.update({
region: "region",
endpoint: "https://dynamodb.region.amazonaws.com"
});
var dynamodb = new AWS.DynamoDB();
var params = {
TableName: "acc_new"
};
dynamodb.describeTable(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(JSON.stringify(data));
});输出:
{ AttributeDefinitions: [ { AttributeName: 'Id', AttributeType: 'S' } ],
TableName: 'acc_new',
KeySchema: [ { AttributeName: 'Id', KeyType: 'HASH' } ],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 } }输出只包含与表关联的键模式(仅哈希键和范围键),而不是所有属性。我想获取与表中的数据相关联的所有属性。
像这样:
{ AttributeName: 'AccountName', AttributeType: 'S' }
{ AttributeName: 'CreatedBy', AttributeType: 'S' }
...
...有没有办法获得包含所有数据字段的dynamoDb表的描述?
发布于 2017-07-03 16:56:56
DynamoDB是一个NoSQL数据库。在创建表时,它并不期望在表中定义所有属性。此外,每一项都可以有任意数量的非键属性。只有键属性在表中的所有项中都是通用的或强制的。
由于上述原因,describe表不能提供表中存在的所有属性。
发布于 2019-01-29 04:30:00
没有传统的方法可以做到这一点,但如果你真的需要这样做,我会这样做:
<代码>G29
- Retrieve all rows from the SQL DB created in (1)
- Parse the file that fired it
- Extract all column names from each row, 1 row at a time
- Compare the column names to the ones found in the SQL DB table. If any are not found, then insert them into the SQL DB. Obviously duplicates would violate PK so be prepared to deal with that error.
在几天或更长时间内(取决于行数),DynamoDB表中的所有列名都将存储在SQL DB中。
发布于 2017-07-03 20:15:18
对于上述情况,不可能列出表中的所有属性。因为Dynamodb是预先定义的NoSql数据库属性,所以在创建表时只定义哈希键和范围键。
https://stackoverflow.com/questions/44880707
复制相似问题