【发布时间】:2018-04-14 10:15:16
【问题描述】:
我正在努力在 firebase cloud firestore 中进行(不是那么)复杂的查询。
我只需要获取所有文档where 和id 字段== 给定的ID。
然后按date 对结果进行排序,并限制为 10 个结果。
这就是我现在的情况
db.firestore().collection('comments')
.where("postId",'==',idOfThePost)
.orderBy('date','asc').limit(10).get().then( snapshot => {
//Nothing happens and the request wasn't even been executed
})
只有当我不使用 orderBy 查询时我才能得到结果,但我必须根据我的应用程序的需要处理这种排序。
有人可以帮我解决这个问题吗?
谢谢
【问题讨论】:
-
这是
idOfThePost的唯一ID吗? -
实际上它是每个帖子的唯一ID,但是相关帖子的每个评论都有一个名为 postId 的字段来标识它所属的帖子。如此多的 cmets 共享相同的
postId值。 -
你如何保存你的约会?
-
date是num格式Date.now()的基本字段。每个文档中有一个日期字段postId和comment -
尝试发送服务器时间戳表单sdk并检查
firebase.firestore.FieldValue.serverTimestamp()
标签: firebase firebase-realtime-database google-cloud-firestore