0

Given the following data structure and ruleset, how would I retrieve all data objects across all keys without knowing the keys upfront?

Database:

{
  "items": {
     "abcd1234": {
       "data" : {"name": "Foo"},
       "users": { "zcds123": true }
     }
  }
}

Rules:

{
  "items": {
     "$itemId": {
       "data" { ".read": true },
       "users": {
         "$uid": {
           ".read": "$uid === auth.uid"
         }
      }
   }
  }
}

I'm trying something like:

firebase.database().ref('items/*/data').once('value');

however calling result.val() returns null. What am I missing?

Is it possible to do this or do I need to put the public data under a separate key?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Jamie Dixon
  • 53,019
  • 19
  • 125
  • 162
  • Firebase security rules cannot be used to filter data. If the user doesn't have access to the location you read from, the operation will immediately fail. If you have public and non-public data, you will indeed need to separate them. See http://stackoverflow.com/questions/38921824/how-to-create-public-private-user-profile-with-firebase-security-rules/38923745#38923745 – Frank van Puffelen Sep 04 '16 at 22:03
  • Btw: `*` does not have a special meaning in a path. So your path refers to a node that is literally named `*`, which probably doesn't exist. That explains why there is no matching data. – Frank van Puffelen Sep 04 '16 at 22:05
  • Thanks for clarifying @FrankvanPuffelen. I've re-architected my data into public and non-public as suggested. Cheers! – Jamie Dixon Sep 05 '16 at 16:29

0 Answers0