简体   繁体   English

用于检索公共和私人聊天消息的 DynamoDB 单一查询

[英]DynamoDB single query to retrieve both public and private chat messages

Need some suggestions in choosing DynamoDB partition key and sort key to retrieve all public and private messages in a chat.在选择 DynamoDB 分区键和排序键以检索聊天中的所有公共和私人消息时需要一些建议。

In the same chat room, users can send public messages and also private messages to specific people.在同一个聊天室中,用户可以向特定的人发送公共消息和私人消息。

DynamoDB model: DynamoDB model:

For public messages: hashkey - chatId; sortKey - timestamp
For private messages: hashkey - chatId; sortKey - userId#timestamp

I'm facing difficulty in choosing primary keys which will return both these type of messages in a single query.我在选择将在单个查询中返回这两种类型的消息的主键时遇到困难。

Off the top of my head I am thinking that you need something in your sortkey so you can use Begins_with and get all the messages.在我的脑海中,我在想你的排序键中需要一些东西,这样你就可以使用 Begins_with 并获取所有消息。 So something like mssg::public::userID::timestamp or mssg::private::timestamp.所以像 mssg::public::userID::timestamp 或 mssg::private::timestamp 这样的东西。

Then you could do a query using chatId as the partition key and then use begins_with mssg on the sort key.然后您可以使用 chatId 作为分区键进行查询,然后在排序键上使用 begin_with mssg。 That'd get all messages for that chatID whether they are public or private.这将获取该 chatID 的所有消息,无论它们是公共的还是私有的。 The next question is what are you doing with the timestamp and do you need to do something with that in this same query?下一个问题是你在用时间戳做什么,你需要在同一个查询中做些什么吗? You did not mention it in your post, but it is in the model example.您在帖子中没有提到它,但它在 model 示例中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM