[REQUIRED] Step 2: Describe your environment
- Android Studio version: 3.2.1
- Firebase Component: Firestore
- Component version: 17.1.1
[REQUIRED] Step 3: Describe the problem
Add a string value to document's array by arrayUnion when the device is offline, the snapshot listener shows it added successfully but later we query by whereArrayContains shows empty result.
Steps to reproduce:
Let's say we have a collection todos containing a single document todo1, which had only one field taskIds as a string array. The schema: https://i.imgur.com/CmAFWgx.png
Step to reproduce:
- Add a snapshot listener to observe data change:
firestore.collection("todos").addSnapshotListener { snapshot, exception ->
snapshot?.documents?.forEach {
Timber.d("todos ${it.data}")
}
}
In the beging the log shows: todos {taskIds=[]}
-
Turn device to offline, kill and re-launch the app.
-
Create a task document with auto-generate id, add the id to document "todo1" by arrayUnion:
firestore.collection("todos")
.document("todo1")
.update("taskIds", FieldValue.arrayUnion(taskId))
The listener at step 1 now shows log: todos {taskIds=[mMifGffC5WEMjALjR6xR]}, so the taskId is added successfully.
- Later, within a click event we query todos collection with
whereArrayContains, either by get():
firestore.collection("todos")
.whereArrayContains("taskIds", taskId)
.get()
.addOnCompleteListener { task ->
Timber.d("size ${task.result?.documents?.size}")
Timber.d("isFromCache ${task.result?.metadata?.isFromCache}")
}
or addSnapshotListener:
firestore.collection("todos")
.whereArrayContains("taskIds", taskId)
.addSnapshotListener { snapshot, exception ->
Timber.d("size ${snapshot?.documents?.size}")
Timber.d("isFromCache ${snapshot?.metadata?.isFromCache}")
}
The result are the same:
But I expect the result size be 1 because document "todo1" should be included.
The same steps work well when device online, both query shows size 1 with addSnapshotListener is from cache and get() isn't.
Any reply were be appreciated, thanks.
[REQUIRED] Step 2: Describe your environment
[REQUIRED] Step 3: Describe the problem
Add a string value to document's array by
arrayUnionwhen the device is offline, the snapshot listener shows it added successfully but later we query bywhereArrayContainsshows empty result.Steps to reproduce:
Let's say we have a collection
todoscontaining a single documenttodo1, which had only one fieldtaskIdsas a string array. The schema: https://i.imgur.com/CmAFWgx.pngStep to reproduce:
In the beging the log shows:
todos {taskIds=[]}Turn device to offline, kill and re-launch the app.
Create a task document with auto-generate id, add the id to document "todo1" by
arrayUnion:The listener at step 1 now shows log:
todos {taskIds=[mMifGffC5WEMjALjR6xR]}, so the taskId is added successfully.whereArrayContains, either byget():or
addSnapshotListener:The result are the same:
But I expect the result size be 1 because document "todo1" should be included.
The same steps work well when device online, both query shows size 1 with
addSnapshotListeneris from cache andget()isn't.Any reply were be appreciated, thanks.