Firebase按自动分配的时间戳检索有限消息

时间:2016-02-28 06:16:37

标签: android firebase

我希望只检索用户在数据库中使用架构的前50条消息:

 "individualMessages" : {
    "99e4989b-a046-4c5f-9478-5ebd8bdc3ded" : {
      "a96da7b1-7c4e-44bc-b82e-fc75bed52bcd" : {
        "-KBUjngi9JStE-k4RMUJ" : {
          "from" : "a96da7b1-7c4e-44bc-b82e-fc75bed52bcd",
          "messageText" : "hey",
          "timeSent" : "2016-02-26 17:40:46"
        },
        "-KBYhsRONfGxVI7Ysb3F" : {
          "from" : "a96da7b1-7c4e-44bc-b82e-fc75bed52bcd",
          "messageText" : "pool",
          "timeSent" : "2016-02-27 12:10:52"
        }
      },
      "fdb17f3a-7b7d-4aa5-9a0b-b9fb33c349de" : {
        "-KBcYtQ5gD-drFZqz_MU" : {
          "from" : "fdb17f3a-7b7d-4aa5-9a0b-b9fb33c349de",
          "messageText" : "ouu",
          "timeSent" : "2016-02-28 10:46:52"
        },
        "-KBcYw24M-9-7H5A3czD" : {
          "from" : "fdb17f3a-7b7d-4aa5-9a0b-b9fb33c349de",
          "messageText" : "gsf",
          "timeSent" : "2016-02-28 10:47:03"
        }

但是,只需使用:

individualMessageMyPath = myFeastFirebase.child("individualMessages").child(.....

getTop50Messages = individualMessageMyPath.limitToLast(5);
getTop50Messages.orderByChild("timeSent").addChildEventListener(mainMessagingListener);

返回该节点上的所有消息。

查看文档这应该有效,但事实并非如此。

缺少什么?

0 个答案:

没有答案