Dynamodb:属性名称和值的占位符

时间:2017-03-21 20:06:40

标签: java database amazon-web-services amazon-dynamodb nosql

我阅读了以下链接,该链接解释了通过表达式属性名称

使用占位符

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ExpressionPlaceholders.html#ExpressionAttributeValues

我的json文档存储如下:

{"user_json": {"profile.title":"abc"} }"

我的java代码如下

        Map<String, String> expressionAttributeNames = new HashMap<String, String>();
        expressionAttributeNames.put("#u1", "user_json.profile.title");

        String projectionExpression = "user_id, #u1";
        QuerySpec spec = new QuerySpec()
            .withProjectionExpression(projectionExpression)
            .withKeyConditionExpression("user_id = :v_id")
            .withNameMap(expressionAttributeNames)
            .withValueMap(new ValueMap()
                .withString(":v_id", userId))
            .withConsistentRead(true);

        ItemCollection<QueryOutcome> items = table.query(spec);
        Iterator<Item> iterator = items.iterator();
        String jsonPretty="";
        while (iterator.hasNext()) {
            jsonPretty = iterator.next().toJSON();
            System.out.println(jsonPretty);
        } 

问题:无法检索包含点的文档路径。

有人可以指出问题吗?感谢

1 个答案:

答案 0 :(得分:2)

尝试这样做:

Map<String, String> expressionAttributeNames = new HashMap<String, String>();
expressionAttributeNames.put("#u1_1", "user_json");
expressionAttributeNames.put("#u1_2", "profile.title");

String projectionExpression = "user_id, #u1_1.#u1_2";