Michel
Michel

Reputation: 11763

Getting last update information / Firebase

When working with a database on Firebase, is it possible from within an iOS app to check the date(& time) a document was last updated using some standard API? I mean without implementing my own system to know when it was last time touched.

It would be convenient if there was a field "lastUpdate" time-stamp for instance.

Upvotes: 6

Views: 7646

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598797

Neither the Firebase Realtime Database nor Cloud Firestore automatically adds a user-readable timestamp field to the data for writes.

If you want such a field, you will have to add it yourself, either from the client, or from Cloud Functions.

For a simple example of the latter, which tracks when a node in the database was last modified, see this folder in the functions-samples repo. The main code:

exports.touch = functions.database.ref('/chat/{message}').onWrite(
    (change, context) => admin.database().ref('/lastmodified').set(context.timestamp));

Upvotes: 9

Related Questions