简体   繁体   English

如何在DynamoDB的扫描中选择嵌套属性?

[英]How to select nested attribute in scan in DynamoDB?

I realize this is answered in the documentation (basically, "use the dot syntax"), but I'm still missing something.我意识到这在文档中得到了回答(基本上,“使用点语法”),但我仍然缺少一些东西。 I'm using the .NET SDK and need to be able to select just a few attributes from a scan, one of which is a boolean inside a Map attribute.我正在使用 .NET SDK,并且需要能够从扫描中选择几个属性,其中之一是 Map 属性中的布尔值。 Note that I'm not trying to filter the results.请注意,我不是要过滤结果。 I want all of the items, but I only want some of the attributes returned to me.我想要所有的物品,但我只想要一些属性还给我。

var config = new ScanOperationConfig
{
    AttributesToGet = new List<string> { "foo.bar" },
    Select = SelectValues.SpecificAttributes
};
var search = Table.Scan(config);
var documents = await search.GetRemainingAsync();

This code gets me the items I expect, but it's missing the "foo.bar" attribute.这段代码让我得到了我期望的项目,但它缺少“foo.bar”属性。 I know I can select the entire foo object, but I'm trying to minimize the amount of data handed back.我知道我可以选择整个foo对象,但我正在尝试尽量减少返回的数据量。 I don't want the other attributes inside the foo object.我不想要foo对象中的其他属性。

The relevant attribute of the item has the following JSON format:项目的相关属性具有以下 JSON 格式:

{
    "foo": {
        "bar": true
    }
}

I checked spelling, case sensitivity, etc. to no avail.我检查了拼写、区分大小写等都无济于事。 Any idea what's wrong?知道出了什么问题吗?

Instead of using Table.Scan , use the AmazonDynamoDBClient and you get more options.而不是使用Table.Scan ,使用AmazonDynamoDBClient ,你会得到更多的选择。

The Client's ScanAsync method takes a ScanRequest which has a ProjectionExpression string.客户端的ScanAsync方法采用具有ProjectionExpression字符串的ScanRequest This is not present on the ScanOperationConfig class and that was the source of confusion.这在ScanOperationConfig类中不存在,这是混淆的根源。

Use the ProjectionExpression like so:像这样使用ProjectionExpression

var scanRequest = new ScanRequest(Table.TableName)
{
    ProjectionExpression = "foo.bar"
};

According to the documentation on ProjectionExpression :根据ProjectionExpression上的文档:

ProjectionExpression replaces the legacy AttributesToGet parameter. ProjectionExpression 替换了旧的 AttributesToGet 参数。

I didn't realize AttributesToGet was legacy until finally looking at the client for a totally unrelated problem and happened to find my answer to this problem.我没有意识到AttributesToGet是遗留问题,直到最终在客户端寻找一个完全不相关的问题并碰巧找到了我对这个问题的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM