【发布时间】:2018-11-13 14:59:21
【问题描述】:
我在 Firestore 中有一个 collection,其中包含接下来 365 天的字符串。它实际上是我们的应用需要在特定日期显示的代码字。
我们注意到,如果用户更改日期并返回应用程序,Firestore 会正确返回当天的代码字,因为我们的查询使用今天的日期来查询代码字。
以前,我们在服务器上有一个定制的 API,它会根据服务器的时间进行获取,以确保不会发生这种情况。
使用 Firestore 复制此行为的最佳方式是什么?我能想到的唯一方法是停止将所有数据存储在数据库中,并每天从服务器托管的文件中注入它。这可能是最好的方法,但想在选择此解决方案之前提出问题。
这是我们当前的查询
const codeword = await firebase
.firestore()
.collection('emoji')
.where('valid_from', '>=', new Date())
.limit(1)
.orderBy('valid_from', 'asc')
.get();
// today's codeword is "whatever" based on the client time
// ... can I use the server's time instead?
【问题讨论】:
标签: javascript firebase google-cloud-firestore