[英]how to make a key unique in dynamodb using nodejs?
I have to make a key unique in dynamo db. 我必须在dynamo db中设置唯一的密钥。 i want to make my email unique, if the email is already existed in database then when i enter next time the same email id then it should not enter to database.
我想使我的电子邮件具有唯一性,如果数据库中已经存在该电子邮件,则当我下次输入相同的电子邮件ID时,则不应输入数据库。 it should give a response "email already exists".
它应该给出一个响应“电子邮件已经存在”。 How can i get that?
我该怎么办?
This is the response which i am getting an employee..in this example i dont need to insert another email value like hari@gmail.com 这是我得到一名雇员的答复。在此示例中,我不需要插入其他电子邮件值,例如hari@gmail.com
{
"defaultEmp": 0,
"empName": "Hari",
"statuses": 1,
"designation": "store keeper",
"id": 1,
"storeId": 1,
"email": "hari@gmail.com"
}
您无需为电子邮件创建ID即可使其唯一。.只需在用户创建帐户时检查db中是否存在该电子邮件即可。.就这样..无需进行其他字段检查。
Choose accordingly, what you want to achieve partition key vs composite key . 相应地选择要实现的分区键和复合键 。
1: you can use the designation as a partition key and email as a sort key Using sort key . 1:您可以将名称用作分区键,将电子邮件用作排序键 。
2: you can use the email as a Partition key and designation as a Sort key or only email as Partition key. 2:您可以将电子邮件用作分区键,而将名称用作排序键,或仅将电子邮件用作分区键。
3: simply select email as Partition key. 3:只需选择电子邮件作为分区密钥。
NOTE: 注意:
-make sure email and designation composite Primary key are unique else it will overwrite data. -确保电子邮件和指定复合主键是唯一的,否则它将覆盖数据。
-This is my first contribution :) Correct me if I am wrong and feel free to give any suggestion. -这是我的第一个贡献:)如果我做错了,请纠正我,并随时提出任何建议。 Thanks!
谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.