amazon web services - AWS DynamoDB Attempting to ADD to a Set - Incorrect Operand -


i creating api using nodejs , dynamodb end. attempting update item add set of "friends". when update user, error, "invalid updateexpression: incorrect operand type operator or function; operator: add, operand type: map". understanding when adding set not exist, set created. if exists, new value should added set. not understand why set attempt add being read map.

how users 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 friends added:

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); }); 

this question has answer here

https://stackoverflow.com/a/38960676/4975772

here's relevant code formatted fit question

let aws = require('aws-sdk'); let docclient = new aws.dynamodb.documentclient();  ...  var params = {     tablename : 'users',     key: {'id': id},     updateexpression : 'add #friends :friendid',     expressionattributenames : {       '#friends' : 'friends'     },     expressionattributevalues : {       ':friendid' : docclient.createset([friendid])     },     returnvalues: 'updated_new' };  docclient.update(params, callback); 

if set doesn't exist, code create you. can run code different set update set's elements. super convenient.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo