title: Android Firestore convert array of document references to List<Pojo>
body: <p>In my Firestore I've got a <code>users</code> collection, within which the documents could have a <code>bookmarks</code> field, which is an array of references:</p>
  
  <p><a href="https://i.stack.imgur.com/Ptuu4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ptuu4.png" alt="Firestore bookmarks example"></a></p>
  
  <p>Each of these references points to a document in the <code>teachers</code> collection:</p>
  
  <p><a href="https://i.stack.imgur.com/4ijeC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4ijeC.png" alt="Teacher example"></a></p>
  
  <p>In my Android app, I want to create a method <code>getBookmarks</code> which returns a <code>List</code> of POJOs each of which represents a teacher. This is what I coded, but I think there are two problems:</p>
  
  <ol>
  <li>I can't return a <code>List&lt;TeacherPojo&gt;</code> to my <code>callback</code>, because I'm getting each document reference singularly</li>
  <li><p>I think that attaching a callback for every item in a collection (which size it's user controlled, a user can have as many bookmarks as he/she wants) could have a high impact on performances.</p>
  
  <pre><code>public void getBookmarks(@NonNull OnSuccessListener&lt;List&lt;TeacherPojo&gt;&gt; callback) 
  {
      checkNotNull(callback);
  
      // document reference points to the user document which is calling this method
      documentReference.get()
          .addOnSuccessListener((documentSnapshot) -&gt; {
              ArrayList&lt;DocumentReference&gt; teacherReferences = (ArrayList&lt;DocumentReference&gt;) documentSnapshot.get("bookmarks");
  
              Iterables.forEach(teacherReferences, (documentReference) -&gt; {
              documentReference.get()
                  .addOnSuccessListener((teacherSnapshot) -&gt; {
                  TeacherPojo teacherPojo = teacherSnapshot.toObject(TeacherPojo.class);
  
                      // now?
                  });
              });
          });
  }
  </code></pre></li>
  </ol>
  
  <p>Is there a better way to code this method, in order to get a <code>List&lt;TeacherPojo&gt;</code> (and possibly without having too impact on performances)?</p>