I'm using firestore in my android application. i'm setting below data class to my document,
data class User(
val uid:String = "",
val address:String = "",
@ServerTimestamp
val upTime: Date? = null
)
In my viewmodel init code im listening to following query,
val filterTime = System.currentTimeMillis() - 7*24*60*60*1000 // Listens to last 7 days of data;
val onlineQueryListener = db.collection("users")
.orderBy("upTime", Query.Direction.DESCENDING)
.whereGreaterThan("uptime", Date(filterTime))
.addSnapShotListener{value,error ->
// do some work
}
On button click, sending new data to server,
val user = User("UserUidComesHere","some address")
db.collection("user").document(user.uid).set(user)
After a button click, the query listener is triggered when online, because the server timestamp will be written with time higher than the filterTime, but when the user is offline, the upTime value will be null and is not getting captured in the query "whereGreaterThan".
so i've added another listener to my init function to listen to the pending wirtes data by adding query for whereEqualTo null for field upTime, but it is not getting triggered.
val offlineQueryListener = db.collection("users")
.orderBy("uptime", Query.Direction.DESCENDING)
.whereEqualTo("uptime", null)
.addSnapShotListener{value,error ->
// do some work
}
Above listener is never triggered. How to overcome the above problem. i wanted to capture null values in the FieldValue.ServerTimeStamp() fields.
question from:
https://stackoverflow.com/questions/66063951/how-to-query-fields-which-has-a-fieldvalue-servertimestamp-value-in-it-in-firest 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…