node.js - DynamoDB conditional update using nodejs -
how conditional update item in dynamodb using nodejs? if exists, increment alone - working expected. struggling in, when item not exists, need add , next iteration onwards increment. got error "the provided expression refers attribute not exist in item".
function increment(data, cb) { const opt = { key: { id: {s: id}, datekey: {s: data.dateval} }, expressionattributevalues: { ':counter': {n: '' + 1}, ':val1': {s: data.val1}, ':val2': {s: data.val2} }, updateexpression: 'set counter=counter+:counter, val1=:val1, val2=:val2',returnvalues: 'updated_new', tablename:tablename }; db.updateitem(opt, (err, data) => { if (err) return cb(err); const counter = getcounter(data.attributes); //private method return cb(null, counter); }); }
Comments
Post a Comment