Adding an item to a deeply nested array using $ADD #1425
-
I'm trying to append a new item to an array nested inside of another array. In the schema below, I'm trying to add a new item to the {
"id": "first-course",
"modules": [
{
"module": "learn-stuff",
"lessonCount": 10,
"completedLessons": [
{
"name": "lesson-1",
"completedDate": 1655956900000
},
{
"name": "lesson-2",
"completedDate": 1655956900000
}
]
},
{
"module": "learn-more-stuff",
...
}
]
} My hope was that I could provide the document path to the nested array like this:
and then use something like this: await Course.update({"id": "first-course},
{ "$ADD": {
"modules[0].completedLessons": {
name: "lesson-3",
completedDate: 1655956999000 }
}
}
); I resorted to adding the completed lesson to the array within the entirety of the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This is currently a limitation in dynamoose. We had a discussion about this here #665 (comment), but I haven't had the time to finish figuring out the implementation. For now I suggest using
I've still needed this occasionally as well, so I may try to find the time to finally take a stab at it in the next few weeks. When I do make progress, I'll be sure to update both on that issue as well as here! |
Beta Was this translation helpful? Give feedback.
This is currently a limitation in dynamoose. We had a discussion about this here #665 (comment), but I haven't had the time to finish figuring out the implementation. For now I suggest using
aws-sdk
directly, and doing something like:I've still needed this occasionally as well, so I may try to find the time to finally take a stab at it in the next few weeks. When I do make progress, I'll be sure to update both on that issue as well as here!