• 14
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Firestore Query won't go into the repsonse

I query firestore with a arrayContain request, and my code goes into the OnSuccess method but it will not go to the for loop. It skips it and goes straight to adding the list to the adapter.

I Debugged it and it just won't go in that for loop.

CollectionReference mRef = FirebaseFirestore.getInstance().collection("movies");
String s = "Captain Marvel";
mRef.whereArrayContains("title", s)
                    .get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
                @Override
                public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                    List<Movie> searchedMovies = new ArrayList<>();
                    for (QueryDocumentSnapshot document : queryDocumentSnapshots) {
                        Movie movie = document.toObject(Movie.class);
                        searchedMovies.add(movie);
                    }
                    mAdapter.addNewMovies(searchedMovies);
                }
});

enter image description here

Your query is returning no results. That's because you're doing an array contains query against a field that is not an array. As far as I can see, title is an string, not an array.

When you receive search results in your OnSuccessListener callback, you should check to see if the QuerySnapshot even contains results before you assume that there are results to iterate. According to the API documentation, there is an isEmpty method you can use to find out if there are results.

Since your title field is a string instead of an array, maybe you should be using a whereEqualTo query instead of whereArrayContains to search it.

  • 1
Reply Report
    • This worked better, I am getting movies to add to the list now. Thanks! But this will only look up title with exact title. I didn't see any methods to search given a partial title. Ex. "title" = "Captain Marvel" and I want to be able to look up this title by just searching "captain".