how to use order by 'token_no' in scan operation
$dynamodb = new AmazonDynamoDB();
$query = array(
'TableName' => $this->token_table,
'AttributesToGet' => array('token_no'),
'ScanFilter' => array(
'queue_id' => array(
'ComparisonOperator' => AmazonDynamoDB::CONDITION_EQUAL,
'AttributeValueList' => array(
array( AmazonDynamoDB::TYPE_STRING => (string)$queue_id)
)
),
'queue_date' => array(
'ComparisonOperator' => AmazonDynamoDB::CONDITION_EQUAL,
'AttributeValueList' => array(
array( AmazonDynamoDB::TYPE_STRING => (string)$date)
)
)
),
);
$scan_response = $dynamodb->scan($query);
You can not specify the sort order for a Scan
operation. The result is sorted by some internal representaton of the HashKey
. So you can not know in which order the items will return.
Only Query
operations return items in a defined order.
Query results are always sorted by the range key. If the data type of the range key is Number, the results are returned in numeric order; otherwise, the results are returned in order of ASCII character code values. By default, the sort order is ascending. To reverse the order use the
ScanIndexForward
parameter set tofalse
.From the AWS DynamoDB Developer Guide