本文介绍了如何使用DynamoDB DocumentClient重写此查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在控制台中测试查询,并想在我的代码中实现它们.我很好奇如何在Node.js代码中获得此代码.我认为这与 QueryFilter 有关,但我一直在努力获取它.

I am testing queries in the console and would like to implement them in my code. I was curious how to get this one in my Node.js code. I think it has something to do with QueryFilter but I am struggling to get it.

let params = {
    TableName: tableName,
    KeyConditionExpression:
      'TimeId = :timeId and begins_with ( TypeKey , :typeKey) ',
    QueryFilter: ?,
    ExpressionAttributeValues: {
      ':timeId': `${year}-${week}`,
      ':typeKey': 'GA',
    },
  };

推荐答案

查询参数应该看起来像这样

The query parms should look something like this

{
  "TableName": "tableName",
  "KeyConditionExpression": "#PK = :timeId And begins_with(#SK, :typeKey)",
  "FilterExpression": "contains(#homeTeam, :team)",
  "ExpressionAttributeValues": {
    ":timeId": {
      "S": "2020-12"
    },
    ":typeKey": {
      "S": "GA"
    },
    ":team": {
      "S": "Value"
    }
  },
  "ExpressionAttributeNames": {
    "#PK": "TimeId",
    "#SK": "TypeKey",
    "#homeTeam": "homeTeam"
  }
}

在学习对DDB进行查询时,请查看 Amazons NoSQL工作台.它具有用于构建操作(例如,更新,删除,查询,扫描等)的漂亮GUI界面,甚至可以生成执行操作的代码.我发现它在面对您的情况下非常有用.

When learning to put together queries for DDB, check out Amazons NoSQL Workbench. It has a nice GUI interface for building operations (e.g. update, delete, query, scan, etc) and will even generate the code to execute the operation. I've found it very useful in situations like your facing.

这篇关于如何使用DynamoDB DocumentClient重写此查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 08:10