I am trying to limit the total number of results that can come back with an iterator to 3. Not the number of results for each iteration. I am hoping to make this number dynamic. However, I cannot find any real answer to accomplish this and the documentation that AWS provides is of no help. Putting the Limit inside array with the table name and keys doesn't limit the results. I also put it in its own separate array but that doesn't work either. The below is what I have tried but I have not been able to get this to work. Any help would be greatly appreciated.
$iterator = $dbh->getIterator('Query', array(
'TableName' => 'raw',
'KeyConditions' => array(
'deviceID' => array(
'AttributeValueList' => array(
array('S' => $deviceID)
),
'ComparisonOperator' => 'EQ'
)
),
'ScanIndexForward' => false // true = ascending, false = descending
),
array(
'Limit' => 3
)
);
Then putting the resulting data into an array. I don't know if I need to do something different here?
foreach ($iterator as $item) {
array_push($resultArray, $item);
}
You might have already tried this, by the looks of it, but try your code with lowercase 'limit'.
$iterator = $dbh->getIterator('Query', array(
'TableName' => 'raw',
'KeyConditions' => array(
'deviceID' => array(
'AttributeValueList' => array(
array('S' => $deviceID)
),
'ComparisonOperator' => 'EQ'
)
),
'ScanIndexForward' => false // true = ascending, false = descending
),
array(
'limit' => 3
)
);
You could also try limiting by doing below.
foreach (new LimitIterator($iterator, 0, 3) as $item) {
array_push($resultArray, $item);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With