【发布时间】:2022-01-21 01:31:39
【问题描述】:
我正在创建一个潜在客户表,其中每个潜在客户都有一个 id (uuid),它是 patrtision 键和 createdAt rangekey。每次将新项目插入潜在客户表时,我都需要执行重复检查
关于运行以下命令
C:\Users\user>aws dynamodb describe-table --table-name serverless-isd-app-leads-dev --endpoint-url http://localhost:8008
这是显示的结果
{
"Table": {
"AttributeDefinitions": [
{
"AttributeName": "id",
"AttributeType": "S"
},
{
"AttributeName": "email",
"AttributeType": "S"
},
{
"AttributeName": "phone",
"AttributeType": "S"
},
{
"AttributeName": "createdAt",
"AttributeType": "N"
}
],
"TableName": "serverless-isd-app-leads-dev",
"KeySchema": [
{
"AttributeName": "id",
"KeyType": "HASH"
},
{
"AttributeName": "createdAt",
"KeyType": "RANGE"
}
],
"TableStatus": "ACTIVE",
"CreationDateTime": "2021-12-18T20:54:11.940000+05:30",
"ProvisionedThroughput": {
"LastIncreaseDateTime": "1970-01-01T05:30:00+05:30",
"LastDecreaseDateTime": "1970-01-01T05:30:00+05:30",
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
},
"TableSizeBytes": 0,
"ItemCount": 0,
"TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/serverless-isd-app-leads-dev",
"GlobalSecondaryIndexes": [
{
"IndexName": "emai_phone_index",
"KeySchema": [
{
"AttributeName": "email",
"KeyType": "HASH"
},
{
"AttributeName": "phone",
"KeyType": "RANGE"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"IndexStatus": "ACTIVE",
"ProvisionedThroughput": {
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
},
"IndexSizeBytes": 0,
"ItemCount": 0,
"IndexArn": "arn:aws:dynamodb:ddblocal:000000000000:table/serverless-isd-app-leads-dev/index/emai_phone_index"
}
]
}
}
这是我的查询参数
const params = {
TableName: process.env.LEADS_TABLE,
IndexName: "emai_phone_index",
Item: {
id: data.id,
email: data.email,
phone: data.phone,
firstName: data.firstName,
lastName: data.lastName,
createdAt: data.createdAt,
updatedAt: data.updatedAt,
},
ConditionExpression:
"attribute_not_exists(#email) AND attribute_not_exists(#phone)",
ExpressionAttributeNames: {
"#email": "email",
"#phone": "phone",
},
};
但由于电子邮件和电话在全球二级索引上,我无法找到它是否重复。
我该如何解决这个问题?或者有没有其他方法来设计一个更好的表
【问题讨论】:
标签: nosql amazon-dynamodb dynamodb-queries