0

My structure:

privateChatsDetails
{
pushKey1{
     lastMessage
          {
          displayName(String)
          photoUrl(String)
          text(String)
          time(Long value)
          uid(String)
          }
     users
          {
          user1Uid
          {
          chat = true
          some other details..
          }
          user2Uid
          {
          chat = true
          some other details..
          }
         }
pushKey2
     lastMessage{...}
     users{...}
....
}

I'm reading all chats into Listview using

mFirebaseDatabaseReference.child("privateChatsDetails").orderByChild("users/" + mUid + "/chat").equalTo(true)

Working perfect, but not ordered well, I'm trying to order by lastMessage/time,

After reading the Index Your Data docs, and some Stackoverflow questions, I tried some rules, no succeeded.

What I have already tried:

  "rules": {   
     "$privateChatsDetails": {
      "lastMessage": {
        ".indexOn": ["time"]
       }
      }  
     }

And:

  "rules": {
    "privateChatsDetails": {
      ".indexOn": ["lastMessage/time"]
    }
  }

And:

  "rules": {
      "privateChatsDetails":{
    "$lastMessageTime": {
        ".indexOn": ["lastMessage/time"]
    }
   }
  }

Any idea? Thanks in advance.

adjuremods
  • 2,938
  • 2
  • 12
  • 17
Nirel
  • 1,855
  • 1
  • 15
  • 26
  • Please edit your question to include how you actually listen/handle the items. That is likely where the problem stems from. – Frank van Puffelen Nov 29 '16 at 17:42
  • Well, I'm using firebase recycle adapter, the problem isn't there. – Nirel Nov 29 '16 at 17:45
  • You're telling the database to order/filter by `chat`, so the results will be ordered by that. They won't be ordered by time. Firebase queries can only order/filter on a single property. See http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen Nov 29 '16 at 18:06
  • 1
    Possibly you are misunderstanding the effect of `.indexOn`. It does not order the result of a query. It only makes queries more efficient. You say "_I'm trying to order by lastMessage/time_". You cannot do that using `.indexOn`. – Bob Snyder Nov 29 '16 at 18:09
  • So there isnt any why to do that? I have to make that order in my app? – Nirel Nov 29 '16 at 20:19

0 Answers0