0

I have a DynamoDB table with animals and I'm interacting with it using Dynamoose. My table has a 'UserId' attribute, that indicates the user that registered that animal. I want to write a query that finds all the animals registered by the same user, i.e., gets all the items that have the attribute 'UserId' matching the input string.

I'm trying to use Dynamoose's queries like this MyModel.query('UserId').eq(user.id).using('UserId-index').exec();, but it always gives this error Index can't be found for query. I imagine that this is caused because it is not finding the index for the attribute 'UserId', but I have an index 'UserId-index' on my table.

I also tried specifying the index that should be used on the query with the using() method, like this MyModel.query('UserId').eq(user.id).using('UserId-index').exec();, but it gave me this other error: Either the KeyConditions or KeyConditionExpression parameter must be specified in the request, which I don't get at all.

Note that I don't wanna use scan(), as the official documentation highly encourages the developers to use query() instead.

G. Hruschka
  • 814
  • 1
  • 6
  • 11
  • Try using the workbench and see if that helps get the syntax going for you: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/workbench.html – easleyfixed Feb 06 '23 at 21:35

0 Answers0