dynamodb-扫描地图包含密钥的项目 [英] dynamodb - scan items where map contains a key

查看:58
本文介绍了dynamodb-扫描地图包含密钥的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,其中包含一个名为appsMap的字段(而非键字段),它看起来像这样:

I have a table that contains a field (not a key field), called appsMap, and it looks like this:

appsMap = { "qa-app": "abc", "another-app": "xyz" }

我要扫描所有其appsMap包含键 qa-app的行(该值并不重要,仅键)。我尝试过类似的方法,但是它不能满足我的需要:

I want to scan all rows whose appsMap contains the key "qa-app" (the value is not important, just the key). I tried something like this but it doesn't work in the way I need:

    FilterExpression = '#appsMap.#app <> :v',
    ExpressionAttributeNames = {
        "#app": "qa-app",
        "#appsMap": "appsMap"
    },
    ExpressionAttributeValues = {
        ":v": { "NULL": True }
    },
    ProjectionExpression  = "deviceID"

正确的语法是什么?

谢谢。

推荐答案

此处对此主题进行了讨论:
https://forums.aws.amazon.com/thread.jspa?threadID=164470

There is a discussion on the subject here: https://forums.aws.amazon.com/thread.jspa?threadID=164470

示例中可能会缺少此部分:
ExpressionAttributeValues:{:name:{ S: Jeff}}

You might be missing this part from the example: ExpressionAttributeValues: {":name":{"S":"Jeff"}}

但是,只是想回应已经说过的内容,扫描是一个昂贵的过程,它遍历每个项目,因此很难扩展数据库。

However, just wanted to echo what was already being said, scan is an expensive procedure that goes through every item and thus making your database hard to scale.

与其他数据库不同,您必须对Dynamo进行大量设置才能使其在出色的性能下运行,这是一个建议:
1)将其转换为根值,例如添加到根中:qaExist,可能的值为0 | 1或true | false。
2)为新创建的值创建二级索引。
3)在新索引上进行查询,并指定0作为搜索参数。

Unlike with other databases, you have to do plenty of setup with Dynamo in order to get it to perform at it's great level, here is a suggestion: 1) Convert this into a root value, for example add to the root: qaExist, with possible values of 0|1 or true|false. 2) Create secondary index for the newly created value. 3) Make query on the new index specifying 0 as a search parameter.

这将使您的系统非常快速且可扩展,无论您有多少条记录以后再去那里。

This will make your system very fast and very scalable regardless of how many records you get in there later on.

这篇关于dynamodb-扫描地图包含密钥的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆