是否可以在 AWS dynamo 数据库中使用虚线字符串命名对象键?或将命令(更新、删除)应用于虚线字符串键?
Is it possible in AWS dynamo database to name object keys with dashed strings? or to apply command (update, delete) to dashed string keys?
我的场景是 aws 中的发电机数据库,我有一个 table 包含如下所示的结构:
{
"data": {
"23fc4fa8-0037-4d09-90be-506eed497a15": {
"text": "first text"
},
"4708f80a-e301-48ab-8351-f598c4300600": {
"text": "second text"
}
},
"types": "type",
"order": 3
}
我的目标是删除第二个文本,我从客户端收到 ID 4708f80a-e301-48ab-8351-f598c4300600
所以我正在构建我的调用以仅删除该字段,以便在删除操作后获得此数据:
{
"data": {
"23fc4fa8-0037-4d09-90be-506eed497a15": {
"text": "first text"
}
},
"types": "type",
"order": 3
}
这是我正在使用的代码:
const type = 'type'
const id = '4708f80a-e301-48ab-8351-f598c4300600'
const dynamoBd = new AWS.DynamoDB.DocumentClient()
const params = {
TableName: DB_TABLE,
Key: {
types: type
},
UpdateExpression : `REMOVE data.${id}`
}
await dynamoDbClient
.update(params, (error, _) => {
if (error) {
console.error(`Error: `, error)
return
}
})
.promise()
但是我收到这个错误:
Error: ValidationException: Invalid UpdateExpression: Syntax error; token: "4708", near: ".4708f80a"
我认为问题是这个字符串的构建方式 'REMOVE data.${id}'
解析后看起来像这样 'REMOVE data.4708f80a-e301-48ab-8351-f598c4300600
'
任何解决此问题的想法,在此先感谢所有可以帮助我的人。 Ps。如果你在 aws 网站上找到了一些关于它的文档,你能不能也 post 它,因为目前我找不到它。再次感谢!
这是构建const params
的方式,在ExpressionAttributeNames
的支持下:
原因是某些键或值可能是关键字或包含特殊字符(如示例中的破折号)。因此 ExpressionAttributeNames
(例如)和 ExpressionAttributeValues
用于创建键和值的替代占位符。
const params = {
TableName: DB_TABLE,
Key: {
types: type
},
UpdateExpression : `REMOVE #data.#id`,
ExpressionAttributeNames: {
'#data': 'data',
'#id': id
}
}
我的场景是 aws 中的发电机数据库,我有一个 table 包含如下所示的结构:
{
"data": {
"23fc4fa8-0037-4d09-90be-506eed497a15": {
"text": "first text"
},
"4708f80a-e301-48ab-8351-f598c4300600": {
"text": "second text"
}
},
"types": "type",
"order": 3
}
我的目标是删除第二个文本,我从客户端收到 ID 4708f80a-e301-48ab-8351-f598c4300600
所以我正在构建我的调用以仅删除该字段,以便在删除操作后获得此数据:
{
"data": {
"23fc4fa8-0037-4d09-90be-506eed497a15": {
"text": "first text"
}
},
"types": "type",
"order": 3
}
这是我正在使用的代码:
const type = 'type'
const id = '4708f80a-e301-48ab-8351-f598c4300600'
const dynamoBd = new AWS.DynamoDB.DocumentClient()
const params = {
TableName: DB_TABLE,
Key: {
types: type
},
UpdateExpression : `REMOVE data.${id}`
}
await dynamoDbClient
.update(params, (error, _) => {
if (error) {
console.error(`Error: `, error)
return
}
})
.promise()
但是我收到这个错误:
Error: ValidationException: Invalid UpdateExpression: Syntax error; token: "4708", near: ".4708f80a"
我认为问题是这个字符串的构建方式 'REMOVE data.${id}'
解析后看起来像这样 'REMOVE data.4708f80a-e301-48ab-8351-f598c4300600
'
任何解决此问题的想法,在此先感谢所有可以帮助我的人。 Ps。如果你在 aws 网站上找到了一些关于它的文档,你能不能也 post 它,因为目前我找不到它。再次感谢!
这是构建const params
的方式,在ExpressionAttributeNames
的支持下:
原因是某些键或值可能是关键字或包含特殊字符(如示例中的破折号)。因此 ExpressionAttributeNames
(例如)和 ExpressionAttributeValues
用于创建键和值的替代占位符。
const params = {
TableName: DB_TABLE,
Key: {
types: type
},
UpdateExpression : `REMOVE #data.#id`,
ExpressionAttributeNames: {
'#data': 'data',
'#id': id
}
}