in firestore/android/FirestoreSnippetsCpp/app/src/main/cpp/snippets.cpp [146:178]
void AddDataSetDocument(firebase::firestore::Firestore* db) {
using firebase::Future;
using firebase::firestore::Error;
using firebase::firestore::FieldValue;
using firebase::firestore::SetOptions;
// To create or overwrite a single document, use the Set() method:
// [START set_document]
// Add a new document in collection 'cities'
db->Collection("cities")
.Document("LA")
.Set({{"name", FieldValue::String("Los Angeles")},
{"state", FieldValue::String("CA")},
{"country", FieldValue::String("USA")}})
.OnCompletion([](const Future<void>& future) {
if (future.error() == Error::kErrorOk) {
std::cout << "DocumentSnapshot successfully written!" << std::endl;
} else {
std::cout << "Error writing document: " << future.error_message()
<< std::endl;
}
});
// [END set_document]
// If the document does not exist, it will be created. If the document does
// exist, its contents will be overwritten with the newly provided data,
// unless you specify that the data should be merged into the existing
// document, as follows:
// [START create_if_missing]
db->Collection("cities").Document("BJ").Set(
{{"capital", FieldValue::Boolean(true)}}, SetOptions::Merge());
// [END create_if_missing]
}