0

I'm extremely new to firebase and need to display all the data in my collection. Within my app there is an integrated quiz function, and when the 'submit score' button is pressed, the data is sent to Firestore as a new document based on the uid.

user collection in firebase, new document based on uid .

This is what I have so far:

    func getData() {
        
      let db = Firestore.firestore()
           
           // Get data
      db.collection("users").getDocuments()
      {
          (querySnapshot, err) in

          if let err = err
          {
              print("Error getting documents: \(err)");
          }
          else
          {
              for document in querySnapshot!.documents {
                self.studentlbl.text = ("\(document.documentID) => \(document.data())");
              }

          }
      }
      

This displays the following: result

I'm trying to figure out how to display the first name, followed by the user's corresponding score.

Thanks

Ywhmki
  • 3
  • 2

1 Answers1

0

You can display the specific field by adding field name in document.data() or doc.data() or the example below:

document.data().firstname;

or in your case(swift) if I'm correct:

self.studentlbl.text = ("(document.data().firstname");

Regarding to the score of the users, I'll recommend creating a new collection to store the data of quiz scores for every users. You can use this answer for user and post as the reference and example that can help you how you can build the database structure of your application. The answer also include how you will query or group it together.

JM Gelilio
  • 3,482
  • 1
  • 11
  • 23