You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think this might just be a lack of my knowledge of DynamoDB again, but I thought that the following test shouldn't throw the error:
'pk' is required
I thought, that because the GSI partitionKey has been specified, that I can run a get query against it without having to include the main table's partitionKey. The error suggests that this is not the case. I'm a bit confused and I'm sure there is a simple answer to this which I'm struggling to find. Any pointer would be greatly appreciated.
const TestTable3 = new Table({
name: 'test-table',
partitionKey: 'pk',
sortKey: 'sk',
indexes: {
GSI1: { partitionKey: 'GSI1sk', sortKey: 'data' },
},
DocumentClient,
})
const TestEntity3 = new Entity({
name: 'TestEntity',
attributes: {
pk: { type: 'string', partitionKey: true },
sk: { type: 'string', partitionKey: 'GSI1', sortKey: true },
data: { type: 'string', sortKey: 'GSI1' },
},
table: TestTable3,
})
describe('get', () => {
it('gets the Key from GSI1 inputs (sync)', async () => {
const { TableName, Key } = TestEntity3.getParams({
sk: 'test-sk', // This is the GSI1 partitionKey I also tried the name `GSI1sk`
data: 'test-data',
})
expect(TableName).toBe('test-table')
expect(Key).toEqual({ sk: 'test-sk', data: 'test-data' })
})
})
The text was updated successfully, but these errors were encountered:
justynspooner
changed the title
Get query on secondary index failing due to requiring PK
v0.2 Get query on secondary index failing due to requiring PK
May 6, 2020
You cannot get an item from a secondary index (this is a DynamoDB thing), you would need to query the GSI instead.
Use this instead:
constpayload=TestTable3.queryParams('test-sk',// your partitionKey on GSI1{eq: 'test-data',// the value of the GSI1 sortKey you want to equalindex: 'GSI1'// the name of the index you are querying})
I think this might just be a lack of my knowledge of DynamoDB again, but I thought that the following test shouldn't throw the error:
'pk' is required
I thought, that because the GSI partitionKey has been specified, that I can run a get query against it without having to include the main table's partitionKey. The error suggests that this is not the case. I'm a bit confused and I'm sure there is a simple answer to this which I'm struggling to find. Any pointer would be greatly appreciated.
The text was updated successfully, but these errors were encountered: