【问题标题】:DynamoDB list_append expression refers error (node.js)DynamoDB list_append 表达式引用错误(node.js)
【发布时间】:2020-02-11 20:10:08
【问题描述】:

我正在尝试将新任务附加到 DynamoDB 上的任务数组中,但出现此错误: "message": "提供的表达式引用了item中不存在的属性"

我在 de DB 中的对象如下所示:

{
  "client_name": "New",
  "information": {
    "git_hub_url": "www.www.www",
    "is_in_production": true,
    "production_url": "www.www.www",
    "project_manager": "Nicolás",
    "tasks": [
      {
        "description": "Esta es una tarea de prueba",
        "estimated_finish_date": "22-10-2020",
        "name": "Tarea 1",
        "owner": "Juanito Laguna",
        "payment_status": "Pagado",
        "payment_type": "Express",
        "price": "$10000",
        "priority": "5",
        "start_date": "22-10-1993",
        "type": "Backend"
      },
      {
        "description": "Esta es una tarea de prueba (también)",
        "estimated_finish_date": "22-10-2010",
        "name": "Tarea 2",
        "owner": "Juanito Perez",
        "payment_status": "Pagado",
        "payment_type": "Express",
        "price": "$10000",
        "priority": "4",
        "start_Date": "22-10-1977",
        "type": "Frontend"
      }
    ]
  },
  "project_name": "testing_project"
}

我的路线是这条:

router.put('/:clientName/:projectName', (req, res) => {
  const { clientName, projectName } = req.params;
  const table = "Clients-Projects";
  const params = {
    TableName:table,
    Key:{
      "client_name": clientName,
      "project_name": projectName
    },
    UpdateExpression: 'SET #tasks = list_append(#tasks, :newTask)',
    ExpressionAttributeNames: {
      '#tasks': 'information.tasks'
    },
    ExpressionAttributeValues: {
      ":newTask": [req.body.newTask]
    },
    ReturnValues:"UPDATED_NEW"
  };
    console.log(params.ExpressionAttributeNames)
  docClient.update(params, (err, data) => {
    if (err) {
      console.error("Unable to update item. Error JSON:", JSON.stringify(err, null, 2));
    } else {
      res.status(200).json(data);
    }
  });
});

我认为我的错误出现在 ExpressionAtributeName 中,但我无法弄清楚(我是 DynamoDB 的新手)。

非常感谢!!!

【问题讨论】:

    标签: javascript node.js amazon-web-services express amazon-dynamodb


    【解决方案1】:

    我已经解决了。 Y 有这个代码:

    const params = {
        TableName:table,
        Key:{
          "client_name": clientName,
          "project_name": projectName
        },
        UpdateExpression: 'SET #tasks = list_append(#tasks, :newTask)',
        ExpressionAttributeNames: {
          '#tasks': 'information.tasks'
        },
        ExpressionAttributeValues: {
          ":newTask": [req.body.newTask]
        },
        ReturnValues:"UPDATED_NEW"
      };
    

    现在我有了这个:

    const params = {
        TableName:table,
        Key:{
          "client_name": clientName,
          "project_name": projectName
        },
        UpdateExpression: 'SET #tasks.tasks = list_append(#tasks.tasks, :newTask)',
        ExpressionAttributeNames: {
          '#tasks': 'information'
        },
        ExpressionAttributeValues: {
          ":newTask": [req.body.newTask]
        },
        ReturnValues:"UPDATED_NEW"
      };
    

    【讨论】:

      猜你喜欢
      • 2020-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多