void ReadDataGetMultipleDocumentsFromCollection()

in firestore/android/FirestoreSnippetsCpp/app/src/main/cpp/snippets.cpp [547:575]


void ReadDataGetMultipleDocumentsFromCollection(
    firebase::firestore::Firestore* db) {
  using firebase::Future;
  using firebase::firestore::DocumentSnapshot;
  using firebase::firestore::Error;
  using firebase::firestore::FieldValue;
  using firebase::firestore::QuerySnapshot;

  // You can also retrieve multiple documents with one request by querying
  // documents in a collection. For example, you can use Where() to query for
  // all of the documents that meet a certain condition, then use Get() to
  // retrieve the results:
  // [START get_multiple]
  db->Collection("cities")
      .WhereEqualTo("capital", FieldValue::Boolean(true))
      .Get()
      .OnCompletion([](const Future<QuerySnapshot>& future) {
        if (future.error() == Error::kErrorOk) {
          for (const DocumentSnapshot& document :
               future.result()->documents()) {
            std::cout << document << std::endl;
          }
        } else {
          std::cout << "Error getting documents: " << future.error_message()
                    << std::endl;
        }
      });
  // [END get_multiple]
}