My document is as follows:
{ "data": { "eventId": "20161029125458-df-d", "name": "first", "purpose": "test", "location": "yokohama", "dateArray": [], "attendees": [ { "attendeeId": "2016102973634-df", "attendeeName": "lakshman", "personalizedDateSelection": {} }, { "attendeeId": "2016102973634-tyyu", "attendeeName": "diwaakar", "personalizedDateSelection": {} } ] } }
Let's say I need to update the member JSON array with attendeeId: 2016102973634-df . I tried many ways with the expression update and condition , but did not succeed.
Here is my attempt:
const params = { TableName: "event", Key: { "eventId": eventId }, UpdateExpression: "SET attendees[???] = ", ConditionExpression: attendees.attendeeId = "2016102973634-df", ExpressionAttributeValues: { ":attendee" : attendeeList }, ReturnValues: "ALL_NEW" }; dynamo.update(params, (err, data) => { if (err) { return reject(err); } console.log(data.Attributes); });
Could not find resources for updating Json in the array.
After the comment by @notionquest: - I did not use JsonMarshaller. I originally added an empty field to the visitors field as follows:
{ "eventId": "20161029125458-df-d", "name": "first", "purpose": "test", "location": "yokohama", "dateArray": [], "attendees": [] }
and then when a new visitor appears, I will add it to the participants property, for example:
const attendee = { "attendeeName": "user1", "personalizedDateSelection": {"today": "free"} } const attendeeList = [attendee]; const eventId = "20161029125458-df-d"; const params = { TableName: "event", Key: { "eventId": eventId }, UpdateExpression: "SET attendees = list_append(attendees, :attendee)", ExpressionAttributeValues: { ":attendee" : attendeeList }, ReturnValues: "ALL_NEW" }; dynamo.update(params, (err, data) => { if (err) { return reject(err); } console.log("in update dynamo"); console.log(data.Attributes); });
As you saw in the above snippets, first I add an empty array [] and add a new member using the code above . Now how to update a specific JSON in an array. If you say that this is not possible, what else can I try?
Should I try the following:
- Get full JSON.
- Manipulate JSOn and change what I want in my node.
- And then upgrade the new JSON to dynamoDB.
- But it consumes two dynamoDB calls that seem inefficient.
I would like to know if there is any round way?