【问题标题】:Query condition missed key schema element: Id in dynamodb查询条件缺少关键架构元素:dynamodb 中的 ID
【发布时间】:2019-08-30 12:00:56
【问题描述】:

我想使用 .query 从表 users 中检索名字为“Peter”的所有数据。我在名为“Id-index”的分区键 ID 上的表上创建了一个索引。但是当我运行代码时,我仍然收到错误 Query condition missing key schema element: Id.

 router.get('/users/query2', (req, res) => {

            var params =
             {
                 TableName: table,
                 IndexName: "Id-index",
                 KeyConditionExpression: "Firstname = :first",
                 //KeyConditionExpression: "Id  = :id",
                 //KeyConditionExpression: "Firstname = :first and Id = :id",
                 //FilterExpression: "Firstname = :first",
                 ExpressionAttributeValues: {
                     ":first": "Peter",
                     //":id": 4

                 }
             }

             let users = docClient.query(params, function (err, data) {
                 if (err) {
                     console.log(err);
                     handleError(err, res);
                 } else {

                     // display all users in the callback
                     // if u use handleSuccess data.Items looses its information
                     res.json({ message: 'success', statusCode: 200, data: data })
                     //handleSuccess(data.Item, res);
                 }
              });

             });

【问题讨论】:

    标签: node.js amazon-dynamodb


    【解决方案1】:

    如果您想通过Firstname 属性查询索引,您应该在该属性上创建索引。 IIUC,您的索引是在Id 属性上创建的,这就是为什么它不允许您在KeyConditionExpression 中指定Firstname 的条件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-06
      • 2019-09-30
      • 2018-05-20
      • 2020-07-15
      • 1970-01-01
      相关资源
      最近更新 更多