skip to Main Content

i have a question. In my PHP Firebase query i have the problem that it seems to only get 20 documents of my database collection.

I am getting all documents data and then push each entry in a separate array to finally sort the entries.

While everything is working so far – i only seem to get 20 entries each time the code runs on my server.

This is my code for fetching the data:

$tracksCount = 0;

$tracksList = $firestore->collection('lists/'.$listId.'/tracks');
    
$tracksDocuments = $tracksList->documents();

$sortedTracks = [];

    foreach ($tracksDocuments as $track) {
        if ($track->exists()) {
            
            
            $trackData = $track->data();
            array_push($sortedTracks, $trackData);

        }
    }



array_multisort( array_column($sortedTracks, "index"), SORT_ASC, $sortedTracks);


    foreach ($sortedTracks as $track) {
            
// pushing fetched data for output....
            $tracksCount = $tracksCount + 1;
    }

This code is indeed working, i am getting all results that are expected – but only for 20 documents. (If there are fewer documents in the collection, it is getting fewer documents aswell. But if more than 20 documents, it has the upper limit for 20)

I cannot find the problem. Maybe somebody can help?

2

Answers


  1. There is no hard limit as such on the maximum number of documents you can request, that would also be not unreasonable.There is actually no documented limit on the number of documents that can be retrieved, although there likely is a physical limit which mostly will depend on the memory and bandwidth of your app.
    There is a maximum depth of functions calls in the security rules for Cloud Firestore.
    If you use the list method of the Firestore REST API, you can set the “pageSize” parameter in the method to specify the maximum number of documents to return, and then paginate this data to be displayed in a readable format while being able to scroll through page navigate and access these lists of documents.
    Also these can be retrieved ID can be passed as an array input , which is something similar you are trying to workaround with.

    Check for similar examples below:

    Login or Signup to reply.
  2. In my case i was fetching firebase collections by simply calling rest request and i was only getting 20 collection objects.

    I was able to get all collections by adding ?pageSize=1000 to the query URL as below.

    https://firestore.googleapis.com/v1/projects/<project-name>/databases/(default)/documents/<collection-name>?pageSize=1000
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search