这几乎完全来自文档(http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Modifying.html),但是像大多数AWS一样,它只是不起作用而且没有完全记录。
以下因0.0025
"The document path provided in the update expression is invalid for update"
这是我正在尝试更新的文档(如AWS管理控制台中的JSON视图所示):
var messageId = "f244ed33-d678-4763-8f46-0f06514d5139"
var sequenceId = "00000000-0000-0000-0000-000000000000"
var now = DateTime.UtcNow;
var lastActivityThreshold = now.Subtract(TimeSpan.FromSeconds(10));
var response = client.UpdateItem(new UpdateItemRequest
{
TableName = "TheTable",
Key = new Dictionary<string, AttributeValue> { { "SequenceId", new AttributeValue { S = sequenceId } } },
ExpressionAttributeValues = new Dictionary<string, AttributeValue>
{
{":MessageId", new AttributeValue {S = messageId}},
{":Now", new AttributeValue {N = now.Ticks.ToString()}},
{":LastActivityThreshold", new AttributeValue {N = lastActivityThreshold.Ticks.ToString() }},
},
UpdateExpression = "REMOVE Messages[0] SET LastActivity = :Now",
ConditionExpression = "Messages[0] <> :MessageId AND (LastActivity <= :LastActivityThreshold OR attribute_not_exists(LastActivity))",
ReturnValues = ReturnValue.UPDATED_NEW
});
我已经尝试了上述代码的许多变体,严格来说要删除所有{
"LastActivity": {
"N": "635753575712635873"
},
"Messages": {
"SS": [
"f244ed33-d678-4763-8f46-0f06514d5139",
"f668d2a5-3a4a-4564-8384-5b5a51c9bad3"
]
},
"SequenceId": {
"S": "00000000-0000-0000-0000-000000000000"
}
}
和ExpressionAttributeValues
并使用ConditionExpression
,但它不起作用并抛出相同的内容错误。
答案 0 :(得分:1)
看起来您正在尝试将文档路径应用于非JSON项目。在集合中没有排序的概念,因此如果要删除第一个项目,则需要将其加载到内存中并对其进行迭代。简而言之,在这种情况下,您需要使用列表。