PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 12, 2022

[FIXED] How Can I Retrieve these data from Firestore?

 September 12, 2022     cross-platform, dart, firebase, flutter, google-cloud-firestore     No comments   

Issue

Firestore Collection

I want to get data from the map in firestore and display it in the List ordered by date?


Solution

That seems to be a single document. You would have to fetch the whole document if you are just going to have a new map for each date. Then sort it yourself using dart.

FirebaseFirestore.instance
    .collection('BMI')
    .doc('docID')
    .get()
    .then((DocumentSnapshot documentSnapshot) {
      if (documentSnapshot.exists) {
        print('Document exists on the database');
        // sort here

        List myList = documentSnapshot.data!.data().entries.map((entry) => entry).toList();
        print(myList);
        // sorting the list
        print(myList.sort((a, b) => a.date.compareTo(b.date)))
      }
    });

You can read more about sorting lists here. If you need to limit number of entries to be fetched then you would have create a dedicated documents for each entry.



Answered By - Dharmaraj
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing