0

I need some guidance in structuring part of my Firebase database. I am familiarising myself with NOSQL dbs and it sometimes feels like I am doing the wrong thing.

I have a main node called Post where I store my blog posts.

I am implementing comments and for that I created another main node(object) named Comment. Each comment has its own unique id user details and the comment itself.

To tie it with the posts, I added under the each post a node called Comment where I store the Unique ID of the comment created in the Comment object.

The problem is when I want to read all the comments from a post I need to make individual requests to Firebase with each Comment unique ID and it does not seem right to me.

What would be the best way to design this structure in order to optimise reading? And how would the query syntax be for a case like this?

This is an iOS Swift project.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
erickva
  • 513
  • 6
  • 17
  • In what programming language? – Laurel May 16 '16 at 23:47
  • 1
    "I need to make individual requests to Firebase with each Comment unique ID and it does not seem right to me". See http://stackoverflow.com/questions/35931526/speed-up-fetching-posts-for-my-social-network-app-by-using-query-instead-of-obse/35932786#35932786 on why this is not as big a problem as you probably think. – Frank van Puffelen May 16 '16 at 23:57
  • This is an iOS - Swift Project – erickva May 17 '16 at 01:54

1 Answers1

-1

This article may also help you, it describes some best practices on how to structure data in Firebase for people who are not used to NoSQL.

From SQL to Firebase — How to structure the DB for a social network app

you need “fanout” your data to multiple locations in the JSON for easier read access.

Basically you duplicate data onto multiple locations (or nodes) in the JSON so it's easier to get the data in your app.

Gil
  • 559
  • 6
  • 18