I need to add a server side timestamp on new documents added to Firestore using a Flutter app. I see I am supposed to use FieldValue.serverTimestamp
but I am not sure where to find this.
Inside the map you should find the timestamp under the corresponding field name, e.g. documentSnapshot. data['FIELD_NAME_HERE'] .
serverTimestamp() to a timestamp on the client. What you can do is write FieldValue. serverTimestamp() to a document on the server, and observe the value that is written to that document. This value will be a valid timestamp.
The FieldValue sentinel for use in a call to set() or update() . public static FieldValue increment (long l) Returns a special value that can be used with set() or update() that tells the server to increment the field's current value by the given value.
As of September 5th, the updated cloud_firestore
v0.8.0 library now has FieldValue.serverTimestamp()
. All is now well in the universe
'timestamp' : Timestamp.now()
Timestamp.now() is part of cloud_firestore;
Example
Screenshot showing that the library is imported from cloud_firestore, and creates a server-generated timestamp in the written data.
Docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With