'Is there a Firestore Timestamp in metadata for Document Creation?

I am wondering if Cloud Firestore timestamps each document on creation in its metadata, and if so, is that metadata available?

I know I can create my own timestamps inside a document for arbitrary reasons, but I'm only interested in when the document itself was created.

Thanks in advance



Solution 1:[1]

I am wondering if Firestore timestamps each document on creation in its metadata

No, it does not.

I know I can create my own timestamps inside a document

That's the solution you should go ahead with. Add the timestamp of the creation as a field within every document.

Edit Jan 21'th 2022:

In Android, you can call DocumentSnapshot.getMetadata() method or QuerySnapshot.getMetadata(), which both return an object of type SnapshotMetadata. By the time I'm editing this answer, in this class there is no method that return a timestamp. There is only a hasPendingWrites() and isFromCache().

So it depends on the platform you are using.

Solution 2:[2]

The accepted answer is actually not true for the latest beta release of firestore, you can access the creation date from the meta data e.g. in python like this:

doc.create_time

in JavaScript you can get the date like this:

const creationDate = new Date(doc.createTime._seconds * 1000)

Just have a look at the documentation: https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1beta1

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Daniel Cukier