简体   繁体   中英

How to query two values from index? Appsync Query Dynamodb

My resolver template

{
   "version" : "2017-02-28",
    "operation" : "Query",
    "query" : {
        "expression" : "receiverusername = :receiverusername and createdat > :createdat",
        "expressionValues" : {
            ":receiverusername" : $util.dynamodb.toDynamoDBJson($context.identity.username),
            ":createdat" : $util.dynamodb.toDynamoDBJson($ctx.args.input.lastDate),
        }
    },
    "index" : "receiverusername-createdat-index",
}

I am trying to query the date and username but I keep on getting this error

{
  "data": {
    "listMyMessages": null
  },
  "errors": [
    {
      "path": [
        "listMyMessages"
      ],
      "data": null,
      "errorType": "DynamoDB:DynamoDbException",
      "errorInfo": null,
      "locations": [
        {
          "line": 2,
          "column": 3,
          "sourceName": null
        }
      ],
      "message": "One or more parameter values were invalid: Condition parameter type does not match schema type (Service: DynamoDb, Status Code: 400, Request ID: 7I18ODEK46H52NMBSF99OTNSQ7VV4KQNSO5AEMVJF66Q9ASUAAJG)"
    }
  ]

How do I query this?

I tried to learn from documentations but nothing gives me any clue!

Querying 2 values at the same time is not possible for DynamoDB, since every GSI creates a duplicate table with different index. A good solution I can think of is querying indexes in parallel and returning their intersaction.

I just did this and it worked. And yes I am not touching or investigating why.

{
    "version" : "2017-02-28",
    "operation" : "Query",
    "index" : "receiverusername-createdat-index",
    "query" : {
        ## Provide a query expression. **
        "expression": "receiverusername = :receiverusername and createdat > :createdat",
        "expressionValues" : {
            ":receiverusername" : {
                "S" : "${context.identity.username}"
            },
            ":createdat": {
                "S": "${ctx.args.lastDate}"
            }
        }
    }
}

I did not use sort key but just index keys

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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