-
-
Couldn't load subscription status.
- Fork 181
How can I add server timestamp to a document? (Firestore) #120
-
Hello, following your documentation, I add val timestamp: Double = ServerValue.TIMESTAMP to my data model.
after adding the document to the firestore DB, I cant see the 'timestamp' field in my firestore console.
and if I create my data model and provide implicit ServerValue.TIMESTAMP, the document contains timestamp with value: 'Infinity'
So my question is- How can I add server timestamp to a document?
how can I get all documents ordered by this timestamp?
@nbransby nbransby
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 3 replies
-
I suspect this is caused by a bug we are tracking here #113
Beta Was this translation helpful? Give feedback.
All reactions
-
@nbransby
Thanks for your reply,
I'm not sure that is a decoding issue...the documentation is not so clear so I will try to describe what I did:
- set Message data class:
@Serializable
data class Message(val name: String, val text: String, val timestamp: Double = ServerValue.TIMESTAMP)
- Push this object to Firestore by:
class RoomChatFirestore(roomId : String) : RoomChat {
private val firebaseFirestore : FirebaseFirestore = Firebase.firestore(Firebase.app)
private val messagesCollection = firebaseFirestore.collection("$ROOT_CHAT_COLLECTION/$roomId/$ROOM_CHAT_MESSAGES_COLLECTION")
override fun sendMessage(name :String, text: String) {
CoroutineScope(GlobalScope.coroutineContext).launch {
val message = Message(name, text)
messagesCollection.add(message, Message.serializer())
}
}
}
- Go to my Firebase console -> Firestore..and this is what I see:
image
as you can see, there is no timestamp field in my message document - is that OK?
if is that OK, how can I observe the collection changes ordered by this timestamp?
Beta Was this translation helpful? Give feedback.
All reactions
-
@nbransby Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.