Reputation: 147
I am developing an app and I am using AWS DynamoDB as the database server. DB is connected with nodeJS. I have a table called chat to store messages. In chat table every item have connectionid as partition key. An item looks like this
{"id": "123456", "messages": [{"id": "1214545","message":"ksadfksfmsfsdf","sender":"112415", "timestamp": "27:1:2022:11:53"}]}
This is a single Item and there are more inside the chat table.
I have been trying to delete a message inside the item. Its easy for me to delete a whole item because connectionid is the partition key. But I want to delete it with respect to id which is nested. How to achieve this?
Upvotes: 0
Views: 170
Reputation: 11496
But I want to delete with respect to id which is nested. How to to achieve this?
No, you cannot. Its not possible to have nested primary key or secondary index on nested key.
I would recommend to remodel your table schema, you can use a composite key for example:
"id": "123456"
as sort key and "id": "1214545" as primary key.Or a very simple solution would be to have message id as your single primary key if it is going to be unique for all record.
Note:- in composite key primary key can have same value but sort key should be different all the time. https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.PrimaryKey
Upvotes: 2