title: how to structure data in Firebase?
body: <p>i come from a MySQL workflow and now i am trying to do something in Firebase, and i have some dilemmas with structuring my data, because i don't know how would i query it.</p>
  
  <p>fallowing the example below where i have some <code>users</code> and some <code>comments</code>, what is a good way to find </p>
  
  <pre><code>how many post likes a user had
  how many post comments a user had
  what were the posts that a user liked
  ...
  </code></pre>
  
  <p>i was thinking on adding that information to a user, like:</p>
  
  <pre><code>  "user:2": {
      "name": "Doe",
      "email": "doe@bob.com",
      "post_likes": {
        "post:1": 1,
        "post:2": 1
      },
      "post_comments": {
        "post:1": 15,
        "post:2": 5
      }
    }
  </code></pre>
  
  <p>but this seems redundant and duplicates data..</p>
  
  <p>i need to find a way to search in <code>posts</code> everything that has to do with <code>user:1</code>, maybe i need to create another object that connects the <code>users</code> and <code>posts</code> ??</p>
  
  <p>any ideas?</p>
  
  <pre><code>{
    "array": {
      "users": {
        "user:1": {
          "name": "John",
          "email": "john@bob.com"
        },
        "user:2": {
          "name": "Doe",
          "email": "doe@bob.com"
        }
      },
      "posts": {
        "post:1": {
          "name": "First Post",
          "content": "some post content",
          "comments": {}
        },
        "post:2": {
          "name": "Second Post",
          "content": "some other post content",
          "likes": 2,
          "comments": {
            "comment:1": {
              "uid": "user:1",
              "email": "some comment"
            },
            "comment:2": {
              "uid": "user:2",
              "email": "some other comment"
            }
          }
        }
      }
    }
  }
  </code></pre>