简体   繁体   English

使用 dynamodb SET 到 append 到一个字符串集

[英]using dynamodb SET to append to a string set

I have looked at recent posts and nothing on them has worked for me.我查看了最近的帖子,但没有任何内容对我有用。 I have a string set called "friendRequests" in my DynamoDB table and I am trying to append an element to it.我的 DynamoDB 表中有一个名为“friendRequests”的字符串集,我正在尝试 append 一个元素。 However, I keep getting many errors when I try to call db.updateItem with these parameters.但是,当我尝试使用这些参数调用 db.updateItem 时,我不断收到很多错误。 Here is my current code, the error is with ExpressionAttributeValues but I have probably spent an hour changing my syntax to no avail.这是我当前的代码,错误与 ExpressionAttributeValues 有关,但我可能花了一个小时更改语法但无济于事。

    var params = {
    TableName: "users",
    Key: { "username": { "S": addFriendInfo.friendUsername } },
    UpdateExpression: "SET friendRequests = list_append(friendRequests, :newFriend)",
    ExpressionAttributeValues: {
        ':newFriend': { "SS" : [addFriendInfo.username] }
    }
}

That is my code above.那是我上面的代码。 addFriendInfo.username / friendUsername are both just strings. addFriendInfo.username / friendUsername 都只是字符串。 This currently gives me a 'Invalid UpdateExpression: Incorrect operand type for operator or function;这目前给了我一个“无效的 UpdateExpression:运算符或 function 的操作数类型不正确; operator or function: list_append, operand type: SS'.运算符或 function:list_append,操作数类型:SS'。 I have tried many things.我尝试了很多东西。 Can anyone point me in right direction to fixing this damn syntax?谁能指出我正确的方向来修复这个该死的语法?

As the DynamoDB documentation explains, DynamoDB has two similar but distinct types - a list and a set .正如DynamoDB 文档所解释的那样,DynamoDB 有两种相似但不同的类型——列表集合 A list is an ordered list of items of any type, while a set is a non-empty, non-ordered collection of items of the same type.列表是任何类型项目的有序列表,而集合是相同类型项目的非空、无序集合。 The "SS" type you used is a "set of strings".您使用的“SS”类型是一组“字符串”。 This is distinct from a "list", and you cannot use list_append on sets, as the error message tells you.这与“列表”不同,您不能在集合上使用list_append ,正如错误消息告诉您的那样。

To add an element to a set (or create a new set if it doesn't yet exist) you can use the ADD operation, eg, ADD friendRequests:newFriend .要将元素添加到集合中(或者创建一个新集合,如果它尚不存在)您可以使用ADD操作,例如ADD friendRequests:newFriend

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM