Adding time to Firestore serverTimestamp()

前端 未结 2 1342
深忆病人
深忆病人 2021-01-20 05:48

Is there a way to add time to a server timestamp without using cloud functions?

What I want is to update a timestamp from a panel, and have the user side check if th

相关标签:
2条回答
  • 2021-01-20 06:04

    You can't perform date math on server timestamps on the client. FieldValue values are just tokens that are interpreted on the server. If you want to do date math using Google server time, you'll have to run that logic on Google servers.

    If you absolutely need to do this on the client, you'll have to write the timestamp in one operation, then read the document back in a second operation, then write the modified date value back to the document in a third operation.

    0 讨论(0)
  • 2021-01-20 06:28

    I'm a pretty old newb, and this is the first question I've read where I might be able to offer something. I really appreciate everything I've leaned here...

    You can't alter timestamps but you can change the timestamps to UNIX time and manipulate them on the server side during doc creation.

    ref.add({expires: firebase.firestore.Timestamp.now().toMillis() + 5000})
    

    Then query based on expires from the front end. Probably not ideal, but when you only have the front end to work with...

    0 讨论(0)
提交回复
热议问题