Firestore-Dokument mit Zusammenführung aktualisieren

Mit Sammlungen den Überblick behalten Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.

Firestore-Dokument mit Zusammenführung aktualisieren

Weitere Informationen

Eine ausführliche Dokumentation, die dieses Codebeispiel enthält, finden Sie hier:

Codebeispiel

C#

DocumentReference docRef = db.Collection("cities").Document("LA");
Dictionary<string, object> update = new Dictionary<string, object>
{
    { "capital", false }
};
await docRef.SetAsync(update, SetOptions.MergeAll);

Go

_, err := client.Collection("cities").Doc("BJ").Set(ctx, map[string]interface{}{
	"capital": true,
}, firestore.MergeAll)

if err != nil {
	// Handle any errors in an appropriate way, such as returning them.
	log.Printf("An error has occurred: %s", err)
}

Java

// asynchronously update doc, create the document if missing
Map<String, Object> update = new HashMap<>();
update.put("capital", true);

ApiFuture<WriteResult> writeResult =
    db.collection("cities").document("BJ").set(update, SetOptions.merge());
// ...
System.out.println("Update time : " + writeResult.get().getUpdateTime());

Node.js

const cityRef = db.collection('cities').doc('BJ');

const res = await cityRef.set({
  capital: true
}, { merge: true });

PHP

$cityRef = $db->collection('samples/php/cities')->document('BJ');
$cityRef->set([
    'capital' => true
], ['merge' => true]);

Python

city_ref = db.collection(u'cities').document(u'BJ')

city_ref.set({
    u'capital': True
}, merge=True)

Ruby

city_ref = firestore.doc "#{collection_path}/LA"
city_ref.set({ capital: false }, merge: true)

Nächste Schritte

Im Google Cloud-Beispielbrowser können Sie Codebeispiele für andere Google Cloud-Produkte suchen und filtern.