ERROR - com.google.firebase.firestore.FirebaseFirestoreException: FAILED_PRECONDITION: The query requires an index

1

Good community, I'm starting to work with the new tool that has recently included FireBase, I mean Cloud Firestore. I'm trying to get a list of documents but I get the following error:

  

com.google.android.gms.tasks.RuntimeExecutionException: com.google.firebase.firestore.FirebaseFirestoreException: FAILED_PRECONDITION: The query requires an index.

In the following line of code:

 ArrayList<DocumentSnapshot> documentos= (ArrayList<DocumentSnapshot>) task.getResult().getDocuments();

I hope you can help me with this which is something new, I leave you the full code of the query, greetings.

db.collection("incidencias").whereEqualTo("activa",true).limit(vez*5).orderBy("t_stamp").get()
            .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                @Override
                public void onComplete(@NonNull Task<QuerySnapshot> task) {
                    ArrayList<DocumentSnapshot> documentos= (ArrayList<DocumentSnapshot>) task.getResult().getDocuments();

                    for(int i=0; i<documentos.size(); i++){
                        DocumentSnapshot datos=documentos.get(i);
                        IncidenciaItem incidenciaItem=new IncidenciaItem(datos.getString("titulo"),
                                datos.getDate("t_stamp"),datos.getString("usuario"),datos.getString("descripcion"),
                                datos.getString("img1"),datos.getString("img2"),datos.getString("img3"),
                                datos.getString("direccion"),datos.getGeoPoint("coordenadas"),String.valueOf(datos.getId()),
                                datos.getBoolean("activa"));

                        lista.add(incidenciaItem);

                    }

                    notificarCambio();

                }
            });
    
asked by Adrián Garrido Blázquez 10.11.2017 в 19:40
source

1 answer

1

I suggest you review the documentation about FAILED_PRECONDITION

  

FAILED_PRECONDITION - Indicates that a condition was not met   prior to the request. The message field in the error response   provides information about the precondition that failed. A cause   possible is to execute a query that requires an index not yet   defined.

Actually indexes are required for this query in Cloud Firestore , you must do it in the Firebase console, in fact when the message is displayed:

  

com.google.android.gms.tasks.RuntimeExecutionException:   com.google.firebase.firestore.FirebaseFirestoreException:   FAILED_PRECONDITION: The query requires an index.

a link should appear which takes you to the console to perform this action.

    
answered by 10.11.2017 / 19:56
source