title: What is the best practice of firestore data structure?
body: <p>I'm making a blog app using firebase.</p>
  
  <p>I want to know the best practice of data structure.</p>
  
  <p>As far as I know, there are 2 case.
  (I'm using react native)</p>
  
  <p>case 1:</p>
  
  <pre><code>posts
    -postID
     -title,content,author(userID),createdDate,favoriteCount
  
  favorites
    -userID
      -favoriteList
        -postID(onlyID)
        -postID(onlyID)
  </code></pre>
  
  <p>In this case, for example, when we need to get favorite posts.</p>
  
  <p></p>
  
  <pre><code>firebase.firestore().collection(`favorites/${userID}/favoriteList`)
      .get()
      .then((snapshot) =&gt; {
        snapshot.forEach((favorite) =&gt; {
          firebase.firestore().collection(`favorites/`).doc(`${favorite.id}`)
            .get()
            .then((post) =&gt; {
            myPostList.push(post.data())
          });
    });
  </code></pre>
  
  <p>in this case, we can't order the favorite posts by <code>createdDate</code>. So, need to sort client side. Even if so, we don't use limit() function.</p>
  
  <p>case 2:</p>
  
  <pre><code>posts
    -postID
    -title,content,author(userID),createdDate,favoriteCount
  
  favorites
    -userID
       -favoriteList
         -postID
           -title,content,author(userID),createdDate,favoriteCount
         -postID
           -title,content,author(userID),createdDate,favoriteCount
  </code></pre>
  
  <p></p>
  
  <pre><code>firebase.firestore().collection(`favorites/${userID}/favoriteList`).orderBy('createdDate','desc').limit(30)
      .get()
      .then((snapshot) =&gt; {
        snapshot.forEach((post) =&gt; {
          myPostList.push(post.data())
        });
    });
  </code></pre>
  
  <p>in this case, When the favorite post is modified by the author,
  we have to update all of the favorite posts. (e.g. If 100 users save the post as a favorite, we have to update to 100 data.)</p>
  
  <p>(And I'm not sure we can increment <code>favoritecount</code> by a transaction, exactly same.)</p>
  
  <p>I think if we use <code>firebase.batch()</code>, we can manage it. But I think it seems Inefficient.</p>
  
  <p>It seems that both ways are not perfect. Do you know the best practice of this case?</p>