0

When I created the messaging app, I forgot to add timestamp to the document. Is there a way to get the timestamp when the firestore document is created?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Masahiro Aoki
  • 815
  • 12
  • 22

2 Answers2

0

Documents don't have any sort of metadata like this. After you create the document, if you didn't originally add a creation timestamp to it, you won't be able to find it after the fact.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
0

Here is what you can do :

// add timestamp field when objective is created. 
exports.objectiveCreationDate = functions.firestore.document('objectives/{documentUid}').onCreate((snap, context) => {
  // New document Created : add field with date
  db.doc(`objectives/${snap.id}`).update({
    creationDate: admin.firestore.FieldValue.serverTimestamp()
  }, {merge: true});
});
Maxime Crtgn
  • 175
  • 2
  • 10