I have a simple Firestore transaction that reads to verify the existence of a document first, and if it doesn't exist, does some write operations.
Code snippet looks something like this
Firestore.firestore().runTransaction({ (transaction, errorPointer) -> Void in let snapshot: DocumentSnapshot // First check if user already exists. let userRef = firestore.document("users/\(user.uid)") do { try snapshot = transaction.getDocument(userRef) } catch let fetchError as NSError { errorPointer?.pointee = fetchError return } if !snapshot.exists { // Document doesn't exist. Start write operation... ... It seems that getDocument does not return a valid snapshot when the document doesn't exist and instead throws an error. I don't want to rely on the error to conclude that the doc doesn't exist (as it can get muddled with other errors).
What would be the proper way to verify a document's existence within a Firestore transaction?