简体   繁体   English

如何查询dynamoDb表属性(不是分区键或排序键)?

[英]How to query dynamoDb table attribute(not a partition key or sort key)?

I have a table that has: 我有一张桌子,上面有:

userId(partition key) postId(sort key) category userId(分区键)postId(排序键)类别

I want to show all items filtered by category? 我要显示按类别过滤的所有项目吗?

How should I do it? 我该怎么办?

My try 我的尝试

    const params = {
    TableName: "posts_reddit",

    KeyConditionExpression: "userId = :userId",
    FilterExpression: "category: category",
    ExpressionAttributeValues: {

        ":userId": event.requestContext.identity.cognitoIdentityId,
        ":category":  "engineering"
    }
};

You missed a colon in your filter expression, it should be: 您错过了过滤器表达式中的冒号,它应该是:

"FilterExpression: "category: :category"

The structure for the ExpressionAttributeValues is not right as well, you must provide which type you're passing as an argument. ExpressionAttributeValues的结构也不正确,您必须提供要作为参数传递的类型。 See ether example in the scan operation docs. 请参阅扫描操作文档中的以太示例。

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

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