Problem with findDocsWithQueryPagingOrderBy

0 votes
It seems like the only function that can retrieve more than 100 results is "findDocsWithQueryPagingOrderBy". We are using it in our custom made leaderboard. We create a query to return us all players that have a score larger than X. It works fine for collections with little documents, but when collection starts to get bigger (thousands of documents), the execution time increases daramatiicaly from 100ms to thousands of ms.

I can guess that this happens because "findDocsWithQueryPagingOrderBy" alsos return the actual documents that satisfy the query, not only their count.

Why not make a function that will just return the count without returning the documents? We really need a function that is fast and simply returns the count of documents that satisfy a given query and can return more than 100.

Please advise!!!
asked Feb 27, 2015 in App42 Cloud API-BaaS by chetruscavladislav (10 points)

1 Answer

0 votes

Ok, figured out the issue myself. 

I was calling this code:

Storage storage = storageService.findDocsWithQueryPagingOrderBy("db_name", "collection_name", query, 0, 0, "key_name", OrderByType.ASCENDING);
int docCount=storage.jsonDocList.size();
The 4th parameter - which is the number of documents to retrieve, is "0", which actually causes to retrieve, attention, ALL documents from the collection, in my case it was 3169!
As soon as i replaced the 4th parameter with "1", like below:
Storage storage = storageService.findDocsWithQueryPagingOrderBy("db_name", "collection_name", query, 1, 0, "key_name", OrderByType.ASCENDING);
and used
I got super fast execution (because only 1 document was retrieved) and a correct answer on number of documents that stasify the given query. So to summarize:
1. Use storage.getRecordCount() to retrieve number of documents that satisfy the query
2. Devs, please analyze the possible bug which results in extracting ALL documents from collection when 4th param is 0.
answered Feb 27, 2015 by chetruscavladislav (10 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