I have message table in dynamodb with the following fields:
Primary partition key => conversation_id
Primary sort key => id
other attributes => message
,date_time
,sender_id
+------------------+----------+----------------------+------------------------+----------+
| conversation_id | id | message | date_time | sender_id|
+----------------------------------------------------+------------------------+----------+
| p1OS9E | S04Ln | Hi.. how are you..? | 2016-11-30 06:58:11 pm | 11 |
| p1OS9E | JZkSo | Work finished..? | 2016-11-30 06:58:13 pm | 11 |
| p1OS9E | EN9N4 | I am fine. | 2016-11-30 06:58:12 pm | 12 |
| | | | | |
| a0zgOO | jmDdm | In online..? | 2016-12-40 08:43:12 pm | 51 |
| a0zgOO | mAEdY | Yes.. say.. | 2016-12-40 08:43:14 pm | 34 |
| a0zgOO | aWKrp | Come to play.. | 2016-12-40 08:43:12 pm | 51 |
+------------------+----------+----------------------+------------------------+----------+
While query items based on partition key, the result returned as unordered(not in inserted order).
The sort key id
, AttributeType is `string', a random generated code to make the Primary key as unique.
First i used date_time
as sort key, but if within same conversation_id
with same date_time
a message will enter. So the data loss may occur.
How to get my items with the order the message get inserted(based on time)..?
Note: I am using PHP (Codeigniter MVC).