Incrementing Data in Firestore's Database

Hi Philomath!

Have you tried this?

let kitchen = db.collection("kitchens").document(kitchenID)
kitchen.updateData([ "usersConnected": FieldValue.increment()])

Documentation reference (bottom of the page, “Increment a numeric value”):
https://firebase.google.com/docs/firestore/manage-data/add-data#increment_a_numeric_value

You could also check for a document’s existence like this:

let kitchen = db.collection("kitchens").document(kitchenID)
kitchen.getDocument { (document, error) in
            if let document = document, document.exists {
                print("document exists")

            } else {
                print("Document does not exist")
            }
        }

Hope this is helpful