baopham/laravel-dynamodb

Trying to sort results by created last

connect-javed001 opened this issue · 3 comments

I am trying to sort result in DESC order by time , I have below table schema :
$params = [
'TableName' => 'Activity',
'KeySchema' => [
[
'AttributeName' => 'userId',
'KeyType' => 'HASH' //Partition key
],
[
'AttributeName' => 'time',
'KeyType' => 'RANGE' //Sort key
]
],
'AttributeDefinitions' => [
[
'AttributeName' => 'userId',
'AttributeType' => 'N'
],
[
'AttributeName' => 'time',
'AttributeType' => 'N'
]

		],
		'ProvisionedThroughput' => [
			'ReadCapacityUnits' => 10,
			'WriteCapacityUnits' => 10
		]
	];

Hash Key -> userId
Sort Key -> time (unique timestamp)

I need to store user activity like : login/signup/logout in dynamodb , Please also give some suggestion ,that how we can store data for every user , in which we will have multiple entries for same user id.

Have you setup $dynamoDbIndexKeys in your model? It might be easier to set an index then use withIndex('time_index').

Is there any way apart from define index ?

Not really no, DynamoDB doesn’t have sortable abilities outside of an index, you can’t just change the sort order whenever you like, it has to already exist in that order in an index.