Get the last record of DynamoDB

1

I'm trying to get the last record of x variable in a dynamoDB table using php. The simple way I had was to get the data for the last 10 minutes and those get the first.

//Ruta de la variable que se quiere obtener
$nameVariable = $this->convertFilter($infoVariable->variableNameDB);

//hora actual - 600 es igual 
//se definen parametros de consulta
$eav = $this->marshaler->marshalJson('{
    ":startStamp": "' . ($this->currentTime - 600) . '",
    ":endStamp": "' . $this->currentTime . '"
}');

Now, the problem with this is that I can no longer guarantee that the last 10 minutes will be data.

I thought maybe expanding the pace but I would have the same problem.

    
asked by Alejo Florez 18.09.2018 в 00:58
source

1 answer

1

According to the documentation, you can use ScanIndexForward :

  

Specify the order for the index travel: if true   (default value), the route is done in ascending order;   if it is false, the route is made in descending order.

     

Items with the same partition key value are stored in   order sorted by classification key. If the data type of the   key classification is numeric (Number), the results are   store in numerical order. For string type (String), the results   they are stored in UTF-8 byte order. For the binary type (Binary),   DynamoDB treats every byte of the binary data as unsigned.

     

If ScanIndexForward is true, DynamoDB returns the results   in the order in which they are stored (by classification key value).   This is the default behavior. If ScanIndexForward is   false, DynamoDB reads the results in reverse order ordering the value   of the key, and then return the results to the client.

From this we can conclude that if you use ScanIndexForward combined with limit you can easily obtain the first or last record as ScanIndexForward is set to true or% false .

For more details and code examples you can check:

answered by 19.09.2018 / 02:55
source