【发布时间】:2017-11-09 07:35:31
【问题描述】:
我有一个帖子列表。每个帖子在createdAt 中包含firebase servervalue timestamp。
假设,我的帖子标题是 1、2、3、4、5。当我做这个查询时。
const userPostsRef = database.ref(`userPosts/${uid}`)
.orderByChild('createdAt').limitToLast(10);`
它仍然返回 1,2,3,4,5。我要的是5,4,3,2,1
我尝试导航时间戳并且它有效。为什么?这是否意味着我必须使用另一个带有负时间戳的子 orderTimestamp 进行反向查询?
更新 json
我的意思是limitToLast();
userPosts
sms|5797235fe618d33da2eb0ad3
-Km2l4HHE3pONRnA2Akp
createdAt: 1496859301233
o: -1496859301233
title: "2"
-Km2l5QQRi1F66LJkM45
createdAt: 1496859305916
o: -1496859305916
title: "3"
-Km2uTa8tAe0G5cJ2U-B
createdAt: 1496861764218
o: -1496861764218
title: "4"
-Km2uUrfwvY90Im06kg4
createdAt: 1496861769435
o: -1496861769435
title: "5"
orderByChild('createdAt')
orderByChild('o')
【问题讨论】:
-
请分享您正在查询的 JSON 的 sn-p(作为文本,没有屏幕截图)。您可以通过单击Firebase Database console 中的“导出 JSON”链接来获取此信息。
-
@FrankvanPuffelen 已更新。
-
我想我明白了。正如@Mathew 的回答,firebase 总是按升序返回,因为 -10 小于 -5,所以它首先返回最新的帖子。
标签: android firebase firebase-realtime-database