Closed mohie93 closed 4 years ago
Appologies for the delay in responding to this! This is expected, but confusing behavior from the Limit parameter on DynamoDB's scan - this limits the maximum number of items returned per page (though the actual number per page may be less than limit
if the size exceeds the 1MB limit). The ItemCollection that is returned by the scan in your code is an Enumerable
which will keep fetching new pages as they are needed (and will eventually page through all of the items).
One way to get the behavior you want is to use the Enumerable#first method, eg:
class ProjectsController < ApplicationController
def index
# This will only request as many pages of results as are required to get params[:limit] items.
projects = Project.scan.first(params[:limit])
end
end
My code :
Model
Controller
Output All records
Also tried
Output All records
But
Output All records as per limit. Can you help to explain why it works only when
.page
is used?