简体   繁体   中英

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.

|          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. Credit to Tamas.

在此处输入图像描述

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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