0

I try to find a way of joining two nodes in Firebase (JSON based structure)

Example data structure:

"users" : {
  "1" : {
    "name" : "Example Name",
    "contacts" : {
        "2" : true,
        "3" : true
    },
    "posts" : {
        "15" : true,
        "28" : true
    }
  },

"posts" : {
  "5" : {
    user : "2",
    date_time : "11.11.2016",
    text : "example text"
  },
  "15" : {
    user : "1",
    date_time : "25.11.2016",
    text : "example text"
  }
}

The user should now have a newsfeed screen, where all posts of all of his contacts are listed. Therefore a join of the two nodes would make the query much more efficient.

Right now I would execute a query for each contact to get the post id's and then have to do a final query to get the actual posts.

EDIT: details and question in comments

Community
  • 1
  • 1
Jonas Ostergaard
  • 319
  • 1
  • 12
  • That sounds like the correct approach. What's the problem/question? – Frank van Puffelen Jan 11 '17 at 14:49
  • Thanks for your comment Frank, I try to figure out the best practice approach in terms of performance. I'm not very experienced with Firebase and try to put most of the computation on database side. EDIT: So to ask a question: what would be the best practice approach for this case with high scalable data? – Jonas Ostergaard Jan 12 '17 at 12:31
  • There is no single best practice. I recommend reading [NoSQL data modeling](https://highlyscalable.wordpress.com/2012/03/01/nosql-data-modeling-techniques/), viewing [Firebase for SQL developers](https://www.youtube.com/playlist?list=PLl-K7zZEsYLlP-k-RKFa7RyNPa9_wCH2s) and studying http://stackoverflow.com/questions/35931526/speed-up-fetching-posts-for-my-social-network-app-by-using-query-instead-of-obse/35932786#35932786. When you have a concrete problem with performance, please post back. – Frank van Puffelen Jan 12 '17 at 15:18

0 Answers0