File tree Expand file tree Collapse file tree 1 file changed +11
-13
lines changed
firestore/app/src/main/java/com/google/example/firestore/kotlin Expand file tree Collapse file tree 1 file changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -433,23 +433,21 @@ abstract class DocSnippets(val db: FirebaseFirestore) {
433433
434434 fun writeBatch () {
435435 // [START write_batch]
436- // Get a new write batch
437- val batch = db.batch()
438-
439- // Set the value of 'NYC'
440436 val nycRef = db.collection(" cities" ).document(" NYC" )
441- batch.set(nycRef, City ())
442-
443- // Update the population of 'SF'
444437 val sfRef = db.collection(" cities" ).document(" SF" )
445- batch.update(sfRef, " population" , 1000000L )
446-
447- // Delete the city 'LA'
448438 val laRef = db.collection(" cities" ).document(" LA" )
449- batch.delete(laRef)
450439
451- // Commit the batch
452- batch.commit().addOnCompleteListener {
440+ // Get a new write batch and commit all write operations
441+ db.runBatch { batch ->
442+ // Set the value of 'NYC'
443+ batch.set(nycRef, City ())
444+
445+ // Update the population of 'SF'
446+ batch.update(sfRef, " population" , 1000000L )
447+
448+ // Delete the city 'LA'
449+ batch.delete(laRef)
450+ }.addOnCompleteListener {
453451 // ...
454452 }
455453 // [END write_batch]
You can’t perform that action at this time.
0 commit comments