以下是使用DocumentClient
的示例代碼。
var AWS = require("aws-sdk");
var creds = new AWS.Credentials('akid', 'secret', 'session');
AWS.config.update({
region : "us-west-2",
endpoint : "http://localhost:8000",
credentials : creds
});
var docClient = new AWS.DynamoDB.DocumentClient();
var table = "Movies";
var year_val = 2015;
var title = "The Big New Movie";
var params = {
TableName : table,
KeyConditionExpression : 'yearkey = :hkey and title = :rkey',
ExpressionAttributeValues : {
':hkey' : year_val,
':rkey' : title
}
};
docClient.query(params, function(err, data) {
if (err) {
console.error("Unable to read item. Error JSON:", JSON.stringify(err,
null, 2));
} else {
console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
}
});
輸出: -
輸出不具有該屬性的數據類型。
GetItem succeeded: {
"Items": [
{
"title": "The Big New Movie",
"yearkey": 2015,
"info": {
"rating": 0,
"plot": "Nothing happens at all."
}
}
],
"Count": 1,
"ScannedCount": 1
}
我建議使用DocumentClient,因爲它會自動爲您轉換所有這些。 '新的AWS.DynamoDB.DocumentClient()' – idbehold