title: Firestore - Difference between DocumentSnapshot and QueryDocumentSnapshot
body: <p>The documentation says</p>
  <blockquote>
  <p>A QueryDocumentSnapshot contains data read from a document in your Firestore database as part of a query. The document is guaranteed to exist and its data can be extracted using the getData() or get() methods.</p>
  <p>QueryDocumentSnapshot offers the same API surface as DocumentSnapshot. Since query results contain only existing documents, the exists() method will always return true and getData() will never be null.</p>
  </blockquote>
  <p><a href="https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/QueryDocumentSnapshot" rel="noreferrer">https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/QueryDocumentSnapshot</a></p>
  <p>But it doesn't explain when I should use one over the other. I tried both in a <code>SnapshotListener</code> on a <code>Collection</code> and both worked.</p>
  <pre><code>protected void onStart() {
      super.onStart();
      notebookRef.addSnapshotListener(new EventListener&lt;QuerySnapshot&gt;() {
          @Override
          public void onEvent(QuerySnapshot queryDocumentSnapshots, FirebaseFirestoreException e) {
              if (e != null) {
                  Toast.makeText(MainActivity.this, &quot;Error while loading!&quot;, Toast.LENGTH_SHORT).show();
                  Log.d(TAG, e.toString());
                  return;
              }
  
              String allNotes = &quot;&quot;;
  
              for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots) {
  
  
                  Note note = documentSnapshot.toObject(Note.class);
  
                  String title = note.getTitle();
                  String description = note.getDescription();
  
                  allNotes += &quot;\nTitle: &quot; + title + &quot; Description: &quot; + description;
  
              }
  
              textViewData.setText(allNotes);
          }
      });
  }
  </code></pre>