[BUG] Cant do a query using secondary index
See original GitHub issueSummary:
I’m try to do a query using a secondary index but it me returns an error
Code sample
const result = await this.Model.query({ [type]: { eq: value } })
.using(index)
.limit(1)
.exec();
Schema
const Schema = new Dynamoose.Schema({
id: {
type: String,
hashKey: true,
default: () => uuid(),
},
cpf: String,
cnpj: String,
status: String,
});
Model
DbIdWallReport:
Type: AWS::DynamoDB::Table
Properties:
TableName: DbIdWallReport
BillingMode: PAY_PER_REQUEST
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: !If [Prod, true, false]
SSESpecification:
SSEEnabled: true
AttributeDefinitions:
- AttributeName: id
AttributeType: S
- AttributeName: idWallNumber
AttributeType: S
- AttributeName: cpf
AttributeType: S
- AttributeName: cnpj
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
GlobalSecondaryIndexes:
- IndexName: IdWallNumberIndex
KeySchema:
- AttributeName: idWallNumber
KeyType: HASH
Projection:
ProjectionType: ALL
- IndexName: IdWallCpfIndex
KeySchema:
- AttributeName: cpf
KeyType: HASH
Projection:
ProjectionType: ALL
- IndexName: IdWallCnpjIndex
KeySchema:
- AttributeName: cnpj
KeyType: HASH
Projection:
ProjectionType: ALL
Tags:
- { Key: Project, Value: !Ref Project }
- { Key: Environment, Value: !Ref Environment }
Current output and behavior (including stack trace):
Returns an error:
WARNING: ValidationException: Either the KeyConditions or KeyConditionExpression parameter must be specified in the request.
Expected output and behavior:
Complete the query and return the result.
Environment:
Operating System: PopOS
Operating System Version: 20.04 LTS
Node.js version (node -v
):12.13.0
NPM version: (npm -v
):6.12.0
Dynamoose version:2.2.1
Other:
- I have read through the Dynamoose documentation before posting this issue
- I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
- I have searched the internet and Stack Overflow to ensure this issue hasn’t been raised or answered before
- I have tested the code provided and am confident it doesn’t work as intended
- I have filled out all fields above
- I am running the latest version of Dynamoose
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
aws dynamodb global secondary index cannot query existing ...
At present, what I suspect is that this data does not seem to be registered in the secondary index. There are 8,357 items...
Read more >Best practices for using secondary indexes in DynamoDB
Secondary indexes are often essential to support the query patterns that your application requires. At the same time, overusing secondary indexes or using...
Read more >Secondary Index Problem | SAP Community
I have problem with my Secondary Index.The problem is that while i am using my Secondary Index field in my query Index is...
Read more >Troubleshooting Secondary Indexes
Describes how to debug and troubleshoot usage of secondary indexes. The following table lists problems you may encounter when using secondary indexes.
Read more >Cassandra at Scale: The Problem with Secondary Indexes
Secondary indexes are indexes built over column values. In other words, let's say you have a user table, which contains a user's email....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@netochaves Ok. The problem is likely that you aren’t defining the indexes within your Schema. https://dynamoosejs.com/guide/Schema#index-boolean--object--array
Thanks so much for this great explanation @fishcharlie, it will help me a lot in my next steps with Dynamo.
Closing this issue now.