Adding time to Firestore serverTimestamp()

微笑、不失礼 提交于 2020-01-30 06:59:47

问题


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 the timestamp is greater than the current time. I also would like for the panel user to be able to set the amount of time to add, so doing the logic on the user side is not an optimal solution.

Example:

document.set({ validTo: firestore.FieldValue.serverTimestamp() + 5000 });

回答1:


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.



来源:https://stackoverflow.com/questions/50563972/adding-time-to-firestore-servertimestamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!