1

I'm building an app on Flutter with Firebase, I've successfully added Firestore and everything works now.

getUsers() async {
    final QuerySnapshot snapshot = await usersRef
        .where("postsCount", isLessThan: 3)
//        .where("username", isEqualTo: "Parzival")
        .getDocuments();

    snapshot.documents.forEach((DocumentSnapshot doc) {
      print(doc.data);
      print(doc.documentID);
      print(doc.exists);
    });

When I run the above cell with the second commented it works !

I want to run a composite query so in the terminal i followed the link google gives to create an Index.

When I manually create an Index there with the the correct fields and successfully enable it, Then I uncomment my line and run it, The terminal shows no error but it also doesn't print the information it was supposed to give.

enter image description here

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Can you add a screenshot of the composite index section for the project? – danh Jul 09 '20 at 14:43
  • I didn't get you, can you elaborate ? Do you mean my code or the image of my index on firebase console ? –  Jul 09 '20 at 14:54
  • I've added it on the post. You can check it out –  Jul 09 '20 at 15:30
  • @DougStevenson Can you explain what you mean ? Note: The `usersRef` is referenced earlier in my dart file as `final usersRef = Firestore.instance.collection('users');` –  Jul 09 '20 at 15:59
  • Does this answer your question? [How to access array index of Cloud Firestore using query in Flutter?](https://stackoverflow.com/questions/55180156/how-to-access-array-index-of-cloud-firestore-using-query-in-flutter) – Harif Velarde Jul 09 '20 at 17:53

1 Answers1

0

I think question is related with another made it here, however I recommend you take a look at this document where you can find useful examples about how to do queries using fluttler.

You could improve your query on this way:

QuerySnapshot snapshot = await sl.get<FirebaseAPI>().getFirestore()
        .collection('usersRef')
        .where("postsCount", isLessThan: 3)
        .where("username", isEqualTo: "Parzival")
        .getDocuments();

Finally I recommend you check this document too.

Harif Velarde
  • 733
  • 5
  • 10
  • Thankyou so much. I'll check it out and let you know. Sorry I don't ask much questions here, I'm not familiar with the custom yet. –  Jul 10 '20 at 08:56