我正在尝试使用以下查询查询firebase数据库:
Query test = mDatabase.orderByChild("creation_date").startAt("-L9H3X-qZZt5WiAdsOKE");
我的数据如下:
-L9H2ea9Ygt0pD5f17Ze
creation_date:
20180904
post_id:
-L9H2ea9Ygt0pD5f17Ze
-L9H3Dmw9gn9lUOV10hK
creation_date:
20180403
post_id:
-L9H3Dmw9gn9lUOV10hK
-L9H3OiIzjegJJuuFSfB
creation_date:
20180302
post_id:
-L9H3OiIzjegJJuuFSfB
-L9H3X-qZZt5WiAdsOKE
creation_date:
20180404
post_id:
-L9H3X-qZZt5WiAdsOKE
-L9JmFch2lnftlMHHiQd
creation_date:
20180405
post_id:
-L9JmFch2lnftlMHHiQd
-L9JueI5x9oFRhOX6a3G
creation_date:
20180405
post_id:
-L9JueI5x9oFRhOX6a3G
我知道订购后它看起来像这样:
-L9H3OiIzjegJJuuFSfB
creation_date:
20180302
post_id:
-L9H3OiIzjegJJuuFSfB
-L9H3Dmw9gn9lUOV10hK
creation_date:
20180403
post_id:
-L9H3Dmw9gn9lUOV10hK
-L9H3X-qZZt5WiAdsOKE
creation_date:
20180404
post_id:
-L9H3X-qZZt5WiAdsOKE
-L9JmFch2lnftlMHHiQd
creation_date:
20180405
post_id:
-L9JmFch2lnftlMHHiQd
-L9JueI5x9oFRhOX6a3G
creation_date:
20180405
post_id:
-L9JueI5x9oFRhOX6a3G
-L9H2ea9Ygt0pD5f17Ze
creation_date:
20180904
post_id:
-L9H2ea9Ygt0pD5f17Ze
我希望查询返回最后四个元素,但它会返回任何内容。
我还在firebase安全规则中添加了一个索引。
任何人都可以帮我弄清楚我做错了吗?
答案 0 :(得分:1)
您需要按孩子的价值排序:
Query test = mDatabase.orderByChild("creation_date").startAt(20180904);
这是-L9H3X-qZZt5WiAdsOKE
随机密钥,它是子creation_date