0

我正在尝试基于 2 个属性搜索表。但是我收到以下错误:

ValidationException:查询条件缺少关键架构元素

我在做什么:

let value = 'dsadsada';
Cache.query({'registration': { 'eq': value}, 'derivativeId': { 'eq': null}}).exec();

预期结果:返回注册与值匹配但导数 ID 为空的文档列表。

我正在使用dynamoose,所以首先这是模型:

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));

这是我serverless定义表的文件:

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'

任何想法我做错了什么?

4

0 回答 0