Я новичок в DynamoDB и NoSQL в целом. Я использовал aws ampify для создания этой таблицы:
{
"Table": {
"AttributeDefinitions": [
{
"AttributeName": "category",
"AttributeType": "S"
},
{
"AttributeName": "id",
"AttributeType": "S"
},
{
"AttributeName": "title",
"AttributeType": "S"
}
],
"TableName": "products2-prod",
"KeySchema": [
{
"AttributeName": "category",
"KeyType": "HASH"
},
{
"AttributeName": "title",
"KeyType": "RANGE"
}
],
"TableStatus": "ACTIVE",
"CreationDateTime": 1574728653.881,
"ProvisionedThroughput": {
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
},
"TableSizeBytes": 0,
"ItemCount": 0,
"TableArn": "arn:aws:dynamodb:xxxxx:table/products2-prod",
"TableId": "7c3ae2a1-cef1-4e52-85e5-b8ef543b0d30",
"GlobalSecondaryIndexes": [
{
"IndexName": "byId",
"KeySchema": [
{
"AttributeName": "id",
"KeyType": "HASH"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"IndexStatus": "ACTIVE",
"ProvisionedThroughput": {
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
},
"IndexSizeBytes": 0,
"ItemCount": 0,
"IndexArn": "arn:aws:dynamodb:xxxxx:table/products2-prod/index/byId"
},
{
"IndexName": "byTitle",
"KeySchema": [
{
"AttributeName": "title",
"KeyType": "HASH"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"IndexStatus": "ACTIVE",
"ProvisionedThroughput": {
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
},
"IndexSizeBytes": 0,
"ItemCount": 0,
"IndexArn": "arn:aws:dynamodb:xxxxx:table/products2-prod/index/byTitle"
}
],
"StreamSpecification": {
"StreamEnabled": true,
"StreamViewType": "NEW_IMAGE"
},
"LatestStreamLabel": "2019-11-26T00:37:33.881",
"LatestStreamArn": "arn:aws:dynamodb:xxxxx:table/products2-prod/stream/2019-11-26T00:37:33.881"
}
}
Я хочу иметь возможность получать элемент только по его названию, поэтому я добавил это в свой файл app.js:
app.get(path + '/name' + '/:title', function(req, res) {
let params = {}
try {
params["title"] = convertUrlType(req.params["title"], "S");
} catch (err) {
res.json({ error: 'Wrong column type ' + err });
}
let getItemParams = {
TableName: tableName,
IndexName: "byTitle",
Key: params
}
dynamodb.get(getItemParams,(err, data) => {
if(err) {
res.statusCode = 500;
res.json({error: 'Could not load items: ' + err.message});
} else {
if (data.Item) {
res.json(data.Item);
} else {
res.json(data) ;
}
}
});
});
Но я получаю эту ошибку, когда пытаюсь получить элемент, используя byTitle GSI:
{"error": "Не удалось загрузить элементы: указанный ключевой элемент не соответствует схеме"}
Любая помощь?