How can I Get more than 5 Documents from a Firestore query?

98 Views Asked by At

I've been working with Firebase Firestore to make a leaderboard for a game I'm making. Here is part of my code:

public void receiveFirestoreData()
    {   //count how many documents have been given loaded
        int counter = 0;
        Query allUsersQuery = db.Collection("Usernames");
        allUsersQuery.GetSnapshotAsync().ContinueWithOnMainThread(task =>
        {
            QuerySnapshot allUsersQuerySnapshot = task.Result;
            foreach (DocumentSnapshot documentSnapshot in allUsersQuerySnapshot.Documents)
            {
                //add one to the counter with each iteration
                counter++;
                Debug.Log("counter: " + counter.ToString());
                Debug.Log($"Document data for {0} document:"+ documentSnapshot.Id);
                
                //the gamer tag of the user
                string username = documentSnapshot.Id;
                GameObject user = allHighScores.transform.Find(helperFunction(counter)).gameObject;
                user.GetComponent<TMPro.TextMeshProUGUI>().text = username;
                
                Dictionary<string, object> encryptedScores = documentSnapshot.ToDictionary();
                foreach (KeyValuePair<string, object> pair in encryptedScores)
                {
                    GameObject score = user.transform.Find("Score").gameObject;
                    string decryptedScore = AesOperation.DecryptString(ScoreManager.key, pair.Value.ToString());
                    score.GetComponent<TMPro.TextMeshProUGUI>().text = decryptedScore;

                
                }    
                
            }
        });
        
    }

In it, I get a snapshot of a Collection called "Usernames" and Documents which are in it. I have 8 Documents in the Collection when I look at it in the Firebase Console. However, the above code always results in 5 Documents given to me. I don't get the final 3. How can I fix this? Doing some research I found out that maybe Firestore has a limit of 10 Documents you can get at once? I'm not sure if that's true. Most of the above code is from the Firebase Docs. Thank you for your help!

It's been hard for me to figure out what it going on here! I tried to see if it was slow internet connectivity but I don't think that's the culprit. I also tried deleting and rewriting the Firestore database but that changed nothing.

Also, the function helperFunction is just a function for me to show each username and score in the correct place in my game hierarchy

0

There are 0 best solutions below