i'm trying to search a table based on 2 attributes. However i'm getting the following error:
ValidationException: Query condition missed key schema element
What i'm doing:
let value = 'dsadsada';
Cache.query({'registration': { 'eq': value}, 'derivativeId': { 'eq': null}}).exec();
Expected result: Return a list of documents where the registration matches the value but the derivativeId is null.
I'm using dynamoose
, so first of all this is the model:
import {model} from "dynamoose";
import {Document} from 'dynamoose/dist/Document';
import {Schema} from 'dynamoose/dist/Schema';
class Cache extends Document {
id: string;
createdAt: Date;
updatedAt: Date;
}
const schema = {
types: {
id: {
type: String,
required: true
},
registration: {
type: String,
index: {
name: 'VehicleLookupIndex',
global: true
}
},
derivativeId: {
type: String,
index: {
name: 'VehicleLookupIndex'
}
}
},
options: {
timestamps: true,
saveUnknown: ['**'],
expires: 10
},
};
model.defaults.set({
create: false,
prefix: process.env.TABLE_PREFIX
});
export default model<Cache>('cache', new Schema(schema.types, schema.options));
This is my serverless
file where I define the table:
cache:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:provider.stage}-${self:service}-cache
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
BillingMode: PAY_PER_REQUEST
GlobalSecondaryIndexes:
- IndexName: 'VehicleLookupIndex'
KeySchema:
- AttributeName: 'id'
KeyType: 'HASH'
Projection:
NonKeyAttributes:
- 'derivativeId'
- 'registration'
ProjectionType: 'INCLUDE'
Any ideas what i'm doing wrong?