DynamoDB DB扫描:在数组中的嵌入式对象上的过滤器

发布于 2025-02-01 20:56:51 字数 1039 浏览 3 评论 0 原文

试图能够过滤看起来像这样的嵌入式对象:

    "posts": [
        {
            "id": "10e85cf7-acd2-417b-a5dc-1dfb6de606bf",
            "references": [
                {
                    "type": "URL",
                    "title": "How to get dynamodb to only return certain columns",
                },
                {
                    "type": "HASHTAG",
                    "title": "#dynamodb",
                },
            ]
        },
...
]

我试图返回具有“主题标签”类型和值“ #dynamodb”的所有帖子。我已经尝试过此操作,但它总是返回null(在node.js中运行):

const params = {
  TableName: "tableName",
  ScanIndexForward: false,
  FilterExpression: "#references.#type = :referenceValue",
  ExpressionAttributeNames: {
    "#references": "references",
    "#type": "HASHTAG"
  },
  ExpressionAttributeValues: {
      ":referenceValue": "#dynamoDB"
  }
}
const response = await docClient.scan(params).promise();
console.log(response);

仅返回(成功)一个空数组。

Trying to be able to filter on embedded object that looks like:

    "posts": [
        {
            "id": "10e85cf7-acd2-417b-a5dc-1dfb6de606bf",
            "references": [
                {
                    "type": "URL",
                    "title": "How to get dynamodb to only return certain columns",
                },
                {
                    "type": "HASHTAG",
                    "title": "#dynamodb",
                },
            ]
        },
...
]

I am trying to return all posts that have reference of type "HASHTAG" and VALUE "#dynamodb". I have tried this but it always returns null (running in node.js):

const params = {
  TableName: "tableName",
  ScanIndexForward: false,
  FilterExpression: "#references.#type = :referenceValue",
  ExpressionAttributeNames: {
    "#references": "references",
    "#type": "HASHTAG"
  },
  ExpressionAttributeValues: {
      ":referenceValue": "#dynamoDB"
  }
}
const response = await docClient.scan(params).promise();
console.log(response);

And only returns (successfully) an empty array.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

↙温凉少女 2025-02-08 20:56:51

使用:MAP 在 #references 指示的路径上。

FilterExpression: 'contains(#references, :map)',
ExpressionAttributeNames: { '#references': 'references' },
ExpressionAttributeValues: {
  ':map': {
    type: 'HASHTAG',
    title: '#dynamodb',
  },
},

Use the contains function to filter on items in a list. In your case, return posts that have an item like :map at the path indicated by #references.

FilterExpression: 'contains(#references, :map)',
ExpressionAttributeNames: { '#references': 'references' },
ExpressionAttributeValues: {
  ':map': {
    type: 'HASHTAG',
    title: '#dynamodb',
  },
},
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文