title: How to make an ArrayList with two Firestore collection?
body: <p>I would like to load RecyclerView from my firestone db. My firestore structure is like this:</p>
  
  <p>users(collection) -> user_id(document) -> books(collection)<br/>
  books(collection) -> book_id(document)</p>
  
  <p>Added: Database structure images<br />
  <a href="https://i.stack.imgur.com/eVjVt.png" rel="nofollow noreferrer">enter image description here</a><br />
  <a href="https://i.stack.imgur.com/VYonZ.png" rel="nofollow noreferrer">enter image description here</a><br />
  <a href="https://i.stack.imgur.com/PcmQL.png" rel="nofollow noreferrer">enter image description here</a><br /></p>
  
  <p>What I want to do is getting the book_ids of current_user into an <code>ArrayList&lt;String&gt;</code>  then with this arraylist and for each loop, I want to load books into another <code>ArrayList&lt;Book&gt;</code>. I am getting the “ArrayList  book_ids” of the current user. (I want to show the books which were added by current user)<br />
  The problem is with this array list I can not manage to get <code>ArrayList&lt;Book&gt;books</code>. I will send this array list to recycler view adapter.</p>
  
  <pre><code>        public void getBookIdsFromDb(){
      final ArrayList&lt;String&gt; myBookIds = new ArrayList&lt;String&gt;();
  
      CollectionReference bookIdRef = db.collection(getString(R.string.collection_users)).document(userId)
              .collection(getString(R.string.colleciton_books));
  
      bookIdRef.get().addOnCompleteListener(new OnCompleteListener&lt;QuerySnapshot&gt;() {
          @Override
          public void onComplete(@NonNull com.google.android.gms.tasks.Task&lt;QuerySnapshot&gt; task) {
              if (task.isSuccessful()){
                  for (DocumentSnapshot ds : task.getResult()){
                      myBookIds.add(ds.getString("book_id"));
                     myBookIds.size());
                  }
                  Log.d(TAG, "onComplete: myBookIds.size" + myBookIds.size());
                  if (myBookIds.size()&gt;0){
                      getMyBooksFromDb(myBookIds);
                      //this works
                  }
  
  
              }
          }
      });
  }
  public void getMyBooksFromDb(ArrayList&lt;String&gt; bookIds){
      final ArrayList&lt;String&gt; myBooksIds =bookIds;
      final ArrayList&lt;Book&gt; myBooks = new ArrayList&lt;Book&gt;();
  
      CollectionReference dbRef = db.collection(getString(R.string.colleciton_books));
      for (int i =0; i&lt;myBooksIds.size();i++){
          Log.d(TAG, "getMyBooksFromDb: myBookIds in for " + myBooksIds.size());
  
  dbRef.document(myBooksIds.get(i)).get().addOnSuccessListener(new OnSuccessListener&lt;DocumentSnapshot&gt;() {
              @Override
              public void onSuccess(DocumentSnapshot documentSnapshot) {
                  if (documentSnapshot != null){
                      Book myBook = documentSnapshot.toObject(Book.class);
                      myBooks.add(myBook);
                      //Can not get out of this array from for loop
                  }
  
              }
          });
      }
  
  }
  
  
  //I tried to make a nested query below but no result :(
  
    public void getBookListFromDb(){
      final ArrayList&lt;String&gt; myBookIds = new ArrayList&lt;String&gt;();
  
      CollectionReference bookIdRef = db.collection(getString(R.string.collection_users)).document(userId)
              .collection(getString(R.string.colleciton_books));
  
      bookIdRef.get().addOnCompleteListener(new OnCompleteListener&lt;QuerySnapshot&gt;() {
          @Override
          public void onComplete(@NonNull com.google.android.gms.tasks.Task&lt;QuerySnapshot&gt; task) {
              final ArrayList&lt;Book&gt; myBooks = new ArrayList&lt;Book&gt;();
              if (task.isSuccessful()){
                  for (DocumentSnapshot ds : task.getResult()){
                      myBookIds.add(ds.getString("book_id"));
                      myBookIds.size();
                  }
                  Log.d(TAG, "onComplete: myBookIds.size" + myBookIds.size());
                  if (myBookIds.size()&gt;0){
                      CollectionReference colRef = db.collection(getString(R.string.colleciton_books));
                      for (int i=0; i&lt; myBookIds.size(); i++){
  
                          colRef.document(myBookIds.get(i)).get().addOnCompleteListener(new OnCompleteListener&lt;DocumentSnapshot&gt;() {
                              @Override
                              public void onComplete(@NonNull com.google.android.gms.tasks.Task&lt;DocumentSnapshot&gt; task) {
                                  if (task.isSuccessful()){
                                      DocumentSnapshot ds = task.getResult();
                                      Book myBook = ds.toObject(Book.class);
                                      myBooks.add(myBook);
                                  }
  
                                  Log.d(TAG, "onComplete: myBooks.size(i) "+ myBooks.size());
                              }
                          });
                          Log.d(TAG, "onComplete: myBooks.size() in for "+ myBooks.size());
                      }
  
                      Log.d(TAG, "onComplete: myBooks.size() "+ myBooks.size());
  
                  }
  
  
              }
          }
      });
  }'
  </code></pre>