0

I'm looking for some guidance on the most optimal way for my application to retrieve user data from Firebase.

For the data structure, I have a db where I have added a "users" child node, and which I then add any user key which has access to this data. For example it looks like.

  • users
    • 32408fhaidsf=sd0ofds : true
    • dd044540-v04r5-0824f: true
    • 43fr45ghh34ggh5567jh: true

I use the OrderbyChild option per the code below. This does work...however I get the firebase warning message: "@firebase/database: FIREBASE WARNING: Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding ".indexOn": "users/QHfNAoleVsfhLJt9dTenCkpCeVu2" at /channels to your security rules for better performance. "

My concern is that as the size of the data grows, is it actually downloading entire table to the client here? That would be extremely problematic. At the same time, I can't see how I can add keys to the /users/ as I append/remove keys based on how users are interacting with the data. I definitely have the need to retrieve data where multiple users can have access to that data.

 addListeners = () => {

    let loadedChannels= [];

    this.state.channelsRef.orderByChild(`users/${this.state.user.uid}`).equalTo(true).on('child_added', snap => {
        if(snap.hasChildren())
       {

               loadedChannels.push(snap.val()); }
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
mike hennessy
  • 1,359
  • 1
  • 16
  • 35
  • Your current data structure allows you to efficiently find all users for a channel, but doesn't allow you to efficiently query all channels for a user. To allow that use-case you'll need to add an additional data structure that the inverse of what you now have. See my answers [here](https://stackoverflow.com/q/40656589) and [here](https://stackoverflow.com/q/27207059) for more info – Frank van Puffelen Apr 24 '19 at 20:16
  • Thanks for the response...this was what I was looking for! The other posts you mentioned provided me what I need to resolve this for scale going forward. – mike hennessy Apr 24 '19 at 23:37
  • Good to hear Mike. Be sure to upvote any of those answer you found useful, so that they become more visible in search traffic. – Frank van Puffelen Apr 25 '19 at 01:10

0 Answers0