在 DynamoDB 中,如果要使用包含空格的属性名称,需要将属性名称放在引号中,并使用表达式属性名称(Expression attribute names)来引用它。
以下是一个使用包含空格的属性名称的示例代码:
var params = {
TableName: "myTable",
KeyConditionExpression: "#attrName = :attrValue",
ExpressionAttributeNames: {
"#attrName": "attribute name with space",
},
ExpressionAttributeValues: {
":attrValue": "value",
},
};
docClient.query(params, function(err, data) {
if (err) {
console.log(err);
} else {
console.log(data);
}
});
在这个示例代码中,属性名称“attribute name with space”包含空格,因此在 KeyExpressionCondition 和 ExpressionAttributeNames 中使用了表达式属性名称。