firebase - 我应该明确存储时间戳吗?

标签 firebase

我正在使用推送将数据添加到列表中的某个位置,我需要根据推送每个项目的时间来分析我获得的列表。

我是否必须在插入的对象中存储时间戳才能执行基于时间的查询?例如:获取时间 x 和时间 y 之间的所有项目

我想确保我做得正确,因为 Firebase 已经使用时间戳来保证每个推送项目的唯一 key

{
data:"Data to be stored",
timestamp: /* time at which the data was pushed, is this important to do time-based query? */
}

最佳答案

如果你想查询时间戳,你确实应该存储时间戳。虽然从技术上讲是可能的 extract the timestamp from Firebase's push ids ,您不应该依赖这样做。

请注意,您将有另一个选择来存储什么值。您想要存储用户发送数据的时间(在 JavaScript Date.now() 中)还是服务器存储数据的时间(使用 Firebase.ServerValue.时间戳)。这些值之间总是存在一些差异。但当用户失去网络连接时,差异可能会变得巨大。由您决定您的用例需要什么逻辑。

关于firebase - 我应该明确存储时间戳吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35126695/

相关文章:

javascript - [Vue 警告] : Property or method "games" is not defined on the instance but referenced during render

android - 存在于 Firebase 数据库用户名

firebase - 实现下拉刷新

firebase - 限制 Firebase 存储路径中的文件数

firebase - 更新 cloud firestore : The operator '[]' isn't defined for the type 'Object' . 后尝试定义操作符 '[]'

android - 错误 :(15, 55) 找不到错误 : cannot access zza class file for com. google.android.gms.common.internal.safeparcel.zza

firebase - firebase 中免费计划的限制

android - 带有多个 Firebase 的 Flutter 应用程序(适用于多环境)

android-studio - 如何让 Google Play 服务 API 和 Firebase API 的 API javadoc 显示在 Android Studio 中,而不是没有文档的反编译类?

swift - 如何从 Firebase 获取特定数据