I am creating an API using Nodejs and DynamoDB as the back end. I am trying to update an item to add to the friends set. When I update a user, I get the error message "Invalid UpdateExpression: invalid operand type for operator or function: operator: ADD, operand type: MAP". I understand that when added to a set that does not exist, the set will be created. If it already exists, the new value should be added to the set. I donβt understand why the set that I am trying to add to the ADD reads like a map.
How users are created:
var params = { TableName: "users", Item:{ "id": Number(id), "name": name, "password": password } }; documentClient.put(params, function(err, data) { if(err) res.json(500, err); else res.json(200, data); });
How to add friends:
var params = { TableName: "users", Key: { "id": id }, UpdateExpression: "ADD friends :friendId", ExpressionAttributeValues: { ":friendId": { "NS": [friendId] } }, ReturnValues: "UPDATED_NEW" }; documentClient.update(params, function(err, data) { if(err) res.json(500, err); else res.json(200, data); });
source share