0

I am using firestore in my application and I had like to sort for all the document which their field "Type" value is "manual" and to sort them according to other field called "DateCreated".

Im trying to do the following but I get no results:

    db.collection( "Items" ).whereEqualTo( "Type", "manual" ).orderBy( "DateCreated", Query.Direction.DESCENDING ).limit( 20).get()
            .addOnSuccessListener( queryDocumentSnapshots -> {
                ....
            } );

Is there any reason that it won't work?

If I cancel the type query then I might get that the 20 returned items are all not from the type I need and therefore no results will be good for me.

Thank you

Ben
  • 1,737
  • 2
  • 30
  • 61
  • 1
    In the future, you should add an error listener to the task and log the exception that gets delivered. It will tell you what to do. In the case of a missing index, it will provide you a link to click that will create the necessary index automatically. – Doug Stevenson Nov 27 '20 at 00:52

1 Answers1

1

You might need an index on "Type". An error message with an URL should be printed in your logcat as well. If you can find that, just click on that URL. Otherwise, try to create one manually..

https://firebase.google.com/docs/firestore/query-data/indexing

sadat
  • 4,004
  • 2
  • 29
  • 49