我正在使用dynamodb为群组创建聊天应用程序 下面是我的表结构
var params = {
TableName: "Chat-test0.5",
KeySchema: [
{AttributeName: "msg_id", KeyType: "HASH"},
{AttributeName: "group_id", KeyType: "RANGE"},
],
AttributeDefinitions: [
{AttributeName: "msg_id", AttributeType: "N"},
{AttributeName: "group_id", AttributeType: "N"},
],
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5
}
};
这是我要插入的数据有效载荷
var params = {
TableName: tableName,
Item: {
msg_id: Date.now(),
group_id: group_id,
"data": {
"user_id": user_id,
"group_id": group_id,
"msg": msg,
"username": user_name,
"msg_date": msg_date,
"timestamp": full_timestamp
}
}
};
数据正确插入。 但主要问题出现在列表中,当我插入多个数据并尝试列出时。它没有按我插入的顺序列出。
所以我想按msy_id
键对数据进行排序。
msg_id
包含Date.now()
值;
那怎么办?