【问题标题】:DynamoDB/Dynalite query not returning query with nodejsDynamoDB/Dynalite 查询不返回使用 nodejs 的查询
【发布时间】:2015-12-21 15:58:57
【问题描述】:

我正在尝试学习 AWS DynamoDB,但遇到了一个看似简单但我无法弄清楚的问题。

我在本地使用在 nodejs 上运行的Dynalite。 错误如下;

{ [ValidationException: KeyConditions 或 KeyConditionExpression 参数必须在请求中指定。] message: '必须在请求中指定 KeyConditions 或 KeyConditionExpression 参数。', 代码:'ValidationException', 时间:2015 年 12 月 21 日星期一 17:31:47 GMT+0200 (SAST), requestId: 'RHDFVDXQTI0VZUIRJSLGRZXJFQJQYWGJOGS0B4MUDSX3H3JSVWNR', 状态码:400, 可重试:假, 重试延迟:0 }

我的表创建如下(为简洁起见,代码被剥离);

var params = {
    TableName : "test",
    KeySchema: [       
      { AttributeName: "email", KeyType: "HASH" },  
      { AttributeName: "date", KeyType: "RANGE" }
    ],
    AttributeDefinitions: [       
        { AttributeName: "email", AttributeType: "S" },
        { AttributeName: "date", AttributeType: "N" }
    ],
    ProvisionedThroughput: {       
        ReadCapacityUnits: 1, 
        WriteCapacityUnits: 1
    }
}

dynamodb.createTable(params, function(err, data) {
    if (err) { console.log(JSON.stringify(err, null, 2)) }
    } else   { console.log(JSON.stringify(data, null, 2)) }
})

测试数据加载如下;

var params = { 
    TableName: 'test',
        Item: {
            "email":   lowerCasedEmail,
            "date":    date,                                                
            "amount":  amount,
        }
    }

  dynamodbDoc.put(params, function(err, data) {
     if (err){
       console.log(JSON.stringify(err, null, 2))
     } else {
        console.log(JSON.stringify(data, null, 2))
     }
  })

然后查询失败如下;

var params = {
    TableName: "test",    
    KeyConditionExpression: "email = :testmail",
    ExpressionAttributeValues: {
      ":testmail": "rik@test.com"
    }
}

dynamodbDoc.query(params, function(err, data) {
   if (err) { console.log(err) } 
   else {
      if (Object.keys(data).length === 0) {
             console.log('Nothing found.')
      } else { console.log(data) }
   }
 })

【问题讨论】:

    标签: amazon-dynamodb


    【解决方案1】:

    我发现了问题。 Dynalite 不能正确处理 KeyConditionExpression。

    【讨论】:

    • 关于这个问题的状态,我一直在关注this issue
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-21
    • 2019-11-26
    • 1970-01-01
    • 2017-09-10
    • 2019-08-22
    • 2016-06-08
    • 1970-01-01
    相关资源
    最近更新 更多