我需要仅使用AWS Stack Build 聊天,最好使用托管的noSQL数据库,例如DynamoDB .
我正在使用dynamoose库 .
let userSchema = new Schema({
id: {
type: String,
hashKey: true
},
conversations: {
type: [String]
}
},{timestamps: true});
let conversaionSchema = new Schema({
id: {
type: String,
hashKey: true
},
participants: {
type: [String],
default: []
},
messages: [String]
}, {
timestamps: true
});
这是我的架构,现在由于某种原因正在对messages数组进行排序并以错误的顺序显示消息,我希望它按时间戳排序 .
对话对象示例:
{
"createdAt": 1544398988371,
"messages": {
"wrapperName": "Set",
"values": [
"{\"body\":\"AS\",\"author\":\"1232131321\",\"createdAt\":1544422180305}",
"{\"body\":\"ASD\",\"author\":\"1232131321\",\"createdAt\":1544422180170}",
"{\"body\":\"D\",\"author\":\"1232131321\",\"createdAt\":1544422180597}",
"{\"body\":\"DAS\",\"author\":\"1232131321\",\"createdAt\":1544422180469}",
"{\"body\":\"aa\",\"author\":\"1232131321\",\"createdAt\":1544422179794}",
"{\"body\":\"ad\",\"author\":\"1232131321\",\"createdAt\":1544422173947}",
"{\"body\":\"ad\",\"author\":\"1232131321\",\"createdAt\":1544422175283}",
"{\"body\":\"as\",\"author\":\"1232131321\",\"createdAt\":1544422172691}",
"{\"body\":\"as\",\"author\":\"1232131321\",\"createdAt\":1544422174265}",
"{\"body\":\"asd\",\"author\":\"1232131321\",\"createdAt\":1544422172380}",
"{\"body\":\"asd\",\"author\":\"1232131321\",\"createdAt\":1544422172533}",
"{\"body\":\"asd\",\"author\":\"1232131321\",\"createdAt\":1544422174121}",
"{\"body\":\"asd\",\"author\":\"1232131321\",\"createdAt\":1544422174913}",
"{\"body\":\"asd\",\"author\":\"1232131321\",\"createdAt\":1544422175089}",
"{\"body\":\"asdadasdasdssad\",\"author\":\"1232131321\",\"createdAt\":1544422077161}",
"{\"body\":\"asdasdasdasdasd\",\"author\":\"1232131321\",\"createdAt\":1544422075546}",
"{\"body\":\"asdfg\",\"author\":\"1232131321\",\"createdAt\":1544422175890}",
"{\"body\":\"asds\",\"author\":\"1232131321\",\"createdAt\":1544422173794}",
"{\"body\":\"asdsa\",\"author\":\"1232131321\",\"createdAt\":1544422169281}",
"{\"body\":\"asdsadasdasdsadsa\",\"author\":\"1232131321\",\"createdAt\":1544422080858}",
"{\"body\":\"asf\",\"author\":\"1232131321\",\"createdAt\":1544422175588}",
"{\"body\":\"d\",\"author\":\"1232131321\",\"createdAt\":1544422173631}",
"{\"body\":\"da\",\"author\":\"1232131321\",\"createdAt\":1544422172988}",
"{\"body\":\"da\",\"author\":\"1232131321\",\"createdAt\":1544422173465}",
"{\"body\":\"das\",\"author\":\"1232131321\",\"createdAt\":1544422172857}",
"{\"body\":\"ds\",\"author\":\"1232131321\",\"createdAt\":1544422173149}",
"{\"body\":\"ds\",\"author\":\"1232131321\",\"createdAt\":1544422173291}",
"{\"body\":\"dsad\",\"author\":\"1232131321\",\"createdAt\":1544422172048}",
"{\"body\":\"dsadasdasdas\",\"author\":\"1232131321\",\"createdAt\":1544422168320}",
"{\"body\":\"sa\",\"author\":\"1232131321\",\"createdAt\":1544422179985}",
"{\"body\":\"sad\",\"author\":\"1232131321\",\"createdAt\":1544422172209}",
"{\"body\":\"sad\",\"author\":\"1232131321\",\"createdAt\":1544422175429}",
"{\"body\":\"sadadasd\",\"author\":\"1232131321\",\"createdAt\":1544422167433}",
"{\"body\":\"sadsadasdsa\",\"author\":\"1232131321\",\"createdAt\":1544422073969}",
"{\"body\":\"sbg\",\"author\":\"1232131321\",\"createdAt\":1544422175732}",
"{\"body\":\"sd\",\"author\":\"1232131321\",\"createdAt\":1544422176025}"
],
"type": "String"
},
"id": "2e700320-fc0c-11e8-9eb1-1995556dbf13",
"participants": {
"wrapperName": "Set",
"values": [
"1232131321",
"24213123131"
],
"type": "String"
},
"updatedAt": 1544422180597
}
我想我需要在messages数组中的createdAt字段上设置rangeKey,这是否可以用DynamoDB?你能分享一个例子吗?最好是动态语法 .