Please Explain How Paging Works

0 votes

Hi,

I have all my users and their corresponding metadata stored in a collection called "profiles". The date they signed up for an account is part of that metadata. This collection could have thousands of records/documents. I want to be able to view the last 10 users who signed up for an account. My approach was to findAllDocumentsByPaging for this "profiles" collection then sort the results by date then display the top ten.

My problem is I really do not understand how paging works and what I am supposed to do to get more than the initial 100 documents. The "find all documents by paging" Corona example in your docs is not Corona code so I'm not sure how to do this. Can you please explain how paging works and give a Corona snippet? I can get the first 100 records but I am unsure how to get more than that and how to tell when I have them all. Do I keep calling the method increasing the offset by 100 until I get an exception?

Thanks,

Scott

 

asked Jul 27, 2017 in Corona by gsglawson (10 points)

1 Answer

0 votes

Hello Scott,

 

Yes you are right, you have to call find all document by paging method until you get the last 100 records. Please find below code snippet for find documents by paging:

local dbName  = "<Your_DataBase_Name>"
local collectionName = "<Your_Collection_Name>"
local max = 5
local offset = 0
local App42CallBack = {}
App42API:initialize("API_KEY","SECRET_KEY")
local storageService = App42API:buildStorageService()
storageService:findAllDocumentsByPaging(dbName, collectionName,max,offset,App42CallBack)
function App42CallBack:onSuccess(object)
print("dbName is "..object:getDbName())
for i=1,table.getn(object:getJsonDocList()) do
print("DocId is "..object:getJsonDocList()[i]:getDocId())
print("CreatedAt is "..object:getJsonDocList()[i]:getCreatedAt())
end
end
function App42CallBack:onException(exception)
print("Message is : "..exception:getMessage())
print("App Error code is : "..exception:getAppErrorCode())
print("Http Error code is "..exception:getHttpErrorCode())
print("Detail is : "..exception:getDetails())
end
 

 

regards,

Himanshu Sharma

answered Jul 28, 2017 by hs00105 (2,005 points)
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...