0
votes

Looking over the the firestore documentation on Batched write https://firebase.google.com/docs/firestore/manage-data/transactions#batched-writes

But, it doesn't say anything about adding a document to a collection.

Anyone know how to do this?

1

1 Answers

2
votes

The setData method (class reference documentation) creates a document if not already existing, or (by default) overwrites the data on that reference path if it already exists.

// Create or overwrite data for document with ID "NYC"
let nycRef = db.collection("cities").document("NYC") 
batch.setData([:], forDocument: nycRef)

// Create a document with a random unique ID
let docRef = db.collection("places").document() 
batch.setData([:], forDocument: docRef)