Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How can I add server timestamp to a document? (Firestore) #120

Unanswered
matanmarciano asked this question in Q&A
Discussion options

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

You must be logged in to vote

Replies: 1 comment 3 replies

Comment options

I suspect this is caused by a bug we are tracking here #113

You must be logged in to vote
3 replies
Comment options

@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:

  1. set Message data class:
@Serializable
data class Message(val name: String, val text: String, val timestamp: Double = ServerValue.TIMESTAMP)
  1. 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())
 }
 }
}
  1. 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?

Comment options

@nbransby Any ideas?

Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /