0

enter image description here

I am trying to get all documents that contain the array called absentDate and in the array it must have the current day. For example since today is 12-28-2020 and document in the image has the array called absentDate and in the array there is a 12-28-2020 string. So my query should have included that document. However when I run the query, no documents show up. All values in the array are string values by the way, if that info makes a difference.

[UPDATE] I have two recyclerview on this activity. One right under the other.

    //Query for Pickup Request
    var pickupQuery = db.collection("Users").whereNotEqualTo("pickupTime", "").orderBy("pickupTime")
    // RecyclerOptions for Pickup Request
    var pickupOptions = pickupFirestoreOptions(pickupQuery)

    pickupAdapter = PickupAdapter(pickupOptions)
    binding.rvPickupList.adapter = pickupAdapter
    binding.rvPickupList.layoutManager = LinearLayoutManager(this)

    // ***** DOESNT WORK ******
    // Query for Absent Request
    val today = LocalDateTime.now()
    val formattedToday = "${today.monthValue}-${today.dayOfMonth}-${today.year}"
    Log.d("TAG", "$formattedToday")
    var absentQuery = db.collection("Users").whereArrayContains("absentDate", formattedToday)
    // RecyclerOptions for Absent Request
    var absentOptions = absentFirestoreOptions(absentQuery)

    absentAdapter = AbsentAdapter(absentOptions)
    binding.rvAbsentList.adapter = absentAdapter
    binding.rvAbsentList.layoutManager = LinearLayoutManager(this)

private fun pickupFirestoreOptions(query: Query): FirestoreRecyclerOptions<PickupData> {
        return FirestoreRecyclerOptions.Builder<PickupData>().setQuery(query, SnapshotParser<PickupData> {
            Log.d("TAG", "pickupFirestoreOptions ran")
            val studentName = "${it.getString("studentFirstName")} ${it.getString("studentLastName")}"
            var atCenter = it.getBoolean("atCenter")!!
            val userId = it.id
            val pickupTime = it.getString("pickupTime")!!
            PickupData(studentName, atCenter, userId, pickupTime)
        }).build()
    }

private fun absentFirestoreOptions(query: Query): FirestoreRecyclerOptions<AbsentData> {
    return FirestoreRecyclerOptions.Builder<AbsentData>().setQuery(query, SnapshotParser<AbsentData> {
       Log.d("TAG", "absentFirestoreOptions ran")
        val studentName = "${it.getString("studentFirstName")} ${it.getString("studentLastName")}"
        AbsentData(studentName)
    }).build()
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 1
    First, log the value of `formattedToday` and make sure it contains exactly what you expect. Also, please edit the question to show the code that examines the results of the query to see how you are observing that no documents match. What you have now isn't actually executing any queries yet. – Doug Stevenson Dec 29 '20 at 02:29
  • I logged the value of formattedToday and it matches exactly what I have in the firestore array. I also posted more of the code. – wombocombo626 Dec 29 '20 at 02:50

1 Answers1

0

Ahhh, I just realized my mistake.

override fun onStart() {
    super.onStart()
    pickupAdapter.startListening()
    absentAdapter.startListening()  <-----------------
}

override fun onDestroy() {
    super.onDestroy()
    pickupAdapter.stopListening()
    absentAdapter.stopListening()  <------------------
}

I forgot to include the startListening() and stopListening() part. So I guess everything was correct but because I didn't startListening() nothing showed up.