0

enter image description here

I have wrote on below rules for Get the value form chats with key createdAt But i cant able to get the values from Firebase DB. Rules are Below

"chats": {
  ".read" : true,
  ".write" : "auth !== null",
      "messages" : {
            ".indexOn": ["userName", "createdAt", "userId"]
        }
},

chats/messages.json?orderBy="createdAt"&startAt=1485920224250&print=pretty

2
  • Could you please edit your original post to clarify what your question is? Your title says you want to write a rule to index nested values in Firebase, but later in your post you say you can't get values. Something else is wrong if you are not returning data from Firebase. Commented Apr 15, 2017 at 15:15
  • I have write the rules for chats/messages.json?orderBy="createdAt"&startAt=1485920224250&print=pretty, but firebase doesnt return anything, kindly advice me what rules need to add in firebase Commented Apr 15, 2017 at 16:09

1 Answer 1

2

You're missing a level in your rules:

"chats": {
  ".read" : true,
  ".write" : "auth !== null",
  "$chatId": {
      "messages" : {
            ".indexOn": ["userName", "createdAt", "userId"]
        }
  }
},
Sign up to request clarification or add additional context in comments.

3 Comments

I Have tried your solution but it throw some error { "error" : "Index not defined, add \".indexOn\": \"createdAt\", for path \"/chats/messages\", to the rules" }
Yeah, I see now that you're trying to get chat rooms based on the timestamp of the messages in them. That won't work. If you want to get the chat rooms in the order of when they were last updates, you must have a property on the chat room that indicates when it was last updated.
@FrankvanPuffelen, but what about indexing both chats AND messages?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.