thu*_*unk 5 timestamp metadata firebase google-cloud-firestore
我想知道 Cloud Firestore 是否在元数据中为每个文档创建时间戳,如果是,该元数据是否可用?
我知道我可以出于任意原因在文档中创建自己的时间戳,但我只对文档本身的创建时间感兴趣。
提前致谢
小智 15
对于最新的 firestore beta 版本来说,接受的答案实际上并不正确,您可以从元数据中访问创建日期,例如在 python 中,如下所示:
doc.create_time
Run Code Online (Sandbox Code Playgroud)
在 JavaScript 中你可以这样获取日期:
const creationDate = new Date(doc.createTime._seconds * 1000)
Run Code Online (Sandbox Code Playgroud)
只需查看文档:https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1beta1
2023 年 4 月 27 日编辑:
在google.firestore.v1中,文档包含nowcreate_time和,两者都是Timestampupdate_time类型。
2022 年 1 月 21 日编辑:
在 Android 中,您可以调用DocumentSnapshot.getMetadata()方法或QuerySnapshot.getMetadata() ,它们都返回SnapshotMetadata类型的对象。当我编辑这个答案时,在这个类中没有返回时间戳的方法。只有hasPendingWrites()和isFromCache()。
我想知道 Firestore 是否在元数据中为每个文档创建时间戳
不,不是的。
我知道我可以在文档中创建自己的时间戳
这就是您应该继续采用的解决方案。将创建时间戳添加为每个文档中的字段。
| 归档时间: |
|
| 查看次数: |
6009 次 |
| 最近记录: |