-
Notifications
You must be signed in to change notification settings - Fork 448
How to set Firestore serverTimestamp on document create / update #736
Comments
hi, I am needing this function too |
It would be useful to know whether or not this property would be the correct one. If so, I can expose it as
|
Hi @EddyVerbruggen, that one seems to be for the Realtime database only (https://firebase.google.com/docs/reference/js/firebase.database.ServerValue). There is a different serverTimestamp for Firestore (https://firebase.google.com/docs/reference/js/firebase.firestore.FieldValue). |
I figured. Btw, you're linking to the JS SDK which I'm not using (instead, the native iOS and Android SDKs). |
Oops, you are right. By the way, I tried using something like this, for Android:
but all I got was an empty object "{}". Was it supposed to work just like that? Or did I miss something? In any case, there seems to be a related issue: flutter/flutter#13905 (comment). |
@ludcila Hmm, looks like we'll need to keep an eye on that issue (subscribe to it), thanks for investigating! |
Did you get the same result? |
I did not check because looking at the comments that should be the case. You can still try adding that |
I see, thanks @EddyVerbruggen! |
At the very bottom of https://firebase.google.com/docs/firestore/manage-data/add-data there's an example for Android on how to do it for the Looks like the Gonna think about how to best approach it. |
If it worked for updates it would be a sufficient workaround. Timestamps become more important in Firestore since the document ids are not created in any meaningful order so the only way to do any kind of time sorting is on the timestamp field. Thanks for looking into it. |
Since ServerValue.TIMESTAMP or FieldValue.serverTimestamp() would not save to Firestore I used Date() as a workaround to set the timestamp. I used the Firestore @ServerTimestamp annotation to save the Date type field to my Firestore database. |
// Get the // Create a document reference // Update the timestamp field with the value from the server Funcionou perfeitamente. Link: server time stamps to specific fields in your documents to track when an update was received by the server |
set() or update() can use firebase.firestore.FieldValue.serverTimestamp(), but not add() |
Hi all, disregard my previous comment as we'll now need to use Timestamp on both client and servers moving forward with the latest version of Firestore.
For my empty Object constructor in Kotlin I'm using ie
|
In case this helps anyone who stumbles upon this issue: |
So this was my scenario: I have an express cloud function that talks to the db...
I thought the property was available on the instance (as in
Also, "timestamp" is not the timestamp I expected - it's more of a That was my experience. |
require('firebase-admin').firestore.FieldValue.serverTimestamp() OR require('firebase-admin').firestore.Timestamp.now()._seconds @kawerewagaba this will work |
Thanks @rajneshbiz . This too happened to work: |
I'd like to be able to automatically add server timestamps for the CRUD operations on the Firestore documents. In this article the recommendation is to use built-in serverTimestamp() function:
const timestamp = firebase.firestore.FieldValue.serverTimestamp() ref.update({ updatedAt: timestamp })
However it appears that the nativescript plugin does not support FieldValue property. What's the recommended way to do this?
Thanks.
The text was updated successfully, but these errors were encountered: