最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the difference between admin.firestore.Timestamp.now() and admin.firestore.FieldValue.serverTimestamp()? -

programmeradmin3浏览0评论

.firestore.FieldValue.html#servertimestamp

.firestore.Timestamp.html#now

I am not sure I understand the difference. Could someone explain this ?

That is: what difference would I obtain if I just used firebase.firestore.Timestamp.now() as a timestamp property of the object I am about to write instead of firebase.firestore.FieldValue.servertimestamp() ?

I would imagine there are some precision gains ? How much ? Or is it something else ?

https://firebase.google./docs/reference/js/firebase.firestore.FieldValue.html#servertimestamp

https://firebase.google./docs/reference/js/firebase.firestore.Timestamp.html#now

I am not sure I understand the difference. Could someone explain this ?

That is: what difference would I obtain if I just used firebase.firestore.Timestamp.now() as a timestamp property of the object I am about to write instead of firebase.firestore.FieldValue.servertimestamp() ?

I would imagine there are some precision gains ? How much ? Or is it something else ?

Share Improve this question asked Feb 15, 2020 at 21:47 TheProgrammerTheProgrammer 1,4994 gold badges30 silver badges54 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 18

Timestamp.now() generates the timestamp using the client machine's clock, which could be wrong, even drastically wrong.

FieldValue.serverTimestamp() encodes a token into the document field that gets translated into a timestamp using the clock on Google's servers whenever the write operation is received (not at the time it was issued from the client). The clock time on all Google services are meticulously guaranteed to be correct, no matter what a malicious user does.

If you absolutely need a correct time, especially one that needs to get checked by security rules using request.time, you should use the server timestamp. If you need the client's clock time, use Timestamp.now(). It's almost always the case that a server timestamp is preferred.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论