0

I am currently developing an app using android studio and Java. This is my first project. I have Implemented Firebase Firestore.

I have a collection that contains my users as documents. For each record, there are field values containing their details. Some are Strings and Some are Numbers.

I have 3 exam types. (please refer attached Images)

I want to get all the Documents from a specific exam type.

and order them according to their marks. (Marks is a number field)

And I want the top 50 students to add to an ArrayList.

How to implement that query? Thanx.

I have tried this

 CollectionReference colref= db.collection("Students");
     colref.whereEqualTo("UpcomingExam", "Grade 5").orderBy("Marks", Query.Direction.DESCENDING).limit(3)
                .get()

ArrayList was Empty. No code errors and also No results. This is only a part of the code... adding to ArrayList with for loop and others working correctly... My only concern is the query.

Firebase Firestore db structure exam type 1

exam type 2

  • I'm not sure I understand the problem/question. The use case is clear, but what isn't working about the code you shared? Is there any error message? If you're asking how to implement the specific query, can you show what you tried for that specific query - so including filtering on all fields you want to filter on? – Frank van Puffelen Jul 13 '23 at 23:22
  • Please edit your question and add the information Frank asked for, and please also respond using @. – Alex Mamo Jul 14 '23 at 06:07
  • @FrankvanPuffelen Really sorry for my bad explanation. I have edited the question. I want to implement that query. Thank you... – Kaushalya Vishwanath Jul 14 '23 at 07:30
  • @AlexMamo I have edited the question. What I want to do is Implement the query... Thanks... – Kaushalya Vishwanath Jul 14 '23 at 07:31
  • Did you create an [index](https://stackoverflow.com/questions/50305328/firestore-whereequalto-orderby-and-limit1-not-working)? – Alex Mamo Jul 14 '23 at 07:55
  • 1
    @AlexMamo It worked. Thanx a lot.... – Kaushalya Vishwanath Jul 14 '23 at 10:10

0 Answers0