in firestore/android/FirestoreSnippetsCpp/app/src/main/cpp/snippets.cpp [67:116]
void QuickstartAddData(firebase::firestore::Firestore* db) {
using firebase::Future;
using firebase::firestore::DocumentReference;
using firebase::firestore::Error;
using firebase::firestore::FieldValue;
// Firestore stores data in Documents, which are stored in Collections.
// Firestore creates collections and documents implicitly the first time
// you add data to the document. You do not need to explicitly create
// collections or documents.
// [START add_ada_lovelace]
// Add a new document with a generated ID
Future<DocumentReference> user_ref =
db->Collection("users").Add({{"first", FieldValue::String("Ada")},
{"last", FieldValue::String("Lovelace")},
{"born", FieldValue::Integer(1815)}});
user_ref.OnCompletion([](const Future<DocumentReference>& future) {
if (future.error() == Error::kErrorOk) {
std::cout << "DocumentSnapshot added with ID: " << future.result()->id()
<< std::endl;
} else {
std::cout << "Error adding document: " << future.error_message() << std::endl;
}
});
// [END add_ada_lovelace]
// Now add another document to the users collection. Notice that this document
// includes a key-value pair (middle name) that does not appear in the first
// document. Documents in a collection can contain different sets of
// information.
// [START add_alan_turing]
db->Collection("users")
.Add({{"first", FieldValue::String("Alan")},
{"middle", FieldValue::String("Mathison")},
{"last", FieldValue::String("Turing")},
{"born", FieldValue::Integer(1912)}})
.OnCompletion([](const Future<DocumentReference>& future) {
if (future.error() == Error::kErrorOk) {
std::cout << "DocumentSnapshot added with ID: "
<< future.result()->id() << std::endl;
} else {
std::cout << "Error adding document: " << future.error_message()
<< std::endl;
}
});
// [END add_alan_turing]
}