简体   繁体   English

DynamoDB 所有记录中唯一的元素列表

[英]DynamoDB Unique list of elements across all records

I have a simple table that stores list of names for a particular record.我有一个简单的表,用于存储特定记录的名称列表。 I want to ensure that a name can never be used for any other record more than once.我想确保一个名称绝不能多次用于任何其他记录。 The names column should also not be empty;名称列也不应为空; there should always be at least 1 given name.应该总是至少有 1 个名字。

|          ID           |          Names                                 |
|-----------------------|------------------------------------------------|
|          111          |          [john, bob]                           |
|          222          |          [tim]                                 |
|          333          |          [bob] (invalid bob already used)      |

Easiest solution I believe for this case is to simply use a 2nd table for the values you are interested in being the primary key.对于这种情况,我认为最简单的解决方案是简单地使用第二个表作为您感兴趣的值作为主键。 Then in application code, simply check that new table if they exist or not to determine if you should create a new record in the primary table.然后在应用程序代码中,只需检查新表是否存在,以确定是否应该在主表中创建新记录。 For a List[L] this simply avoids having to traverse every single list of every record to determine if a particular scalar value already exists or not.对于 List[L] 这只是避免了必须遍历每个记录的每个列表以确定特定标量值是否已经存在。 Credit to Tamas.感谢塔马斯。

在此处输入图像描述

https://advancedweb.hu/how-to-properly-implement-unique-constraints-in-dynamodb/ https://advancedweb.hu/how-to-properly-implement-unique-constraints-in-dynamodb/

Here's a blog post describing how to best enforce uniqueness constraints: https://aws.amazon.com/blogs/database/simulating-amazon-dynamodb-unique-constraints-using-transactions/这是一篇描述如何最好地执行唯一性约束的博客文章: https://aws.amazon.com/blogs/database/simulating-amazon-dynamodb-unique-constraints-using-transactions/

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

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