Q:

Firestore "updateData" removes all the fields in document

In my prpject I have a "employees" collection where every employee document containes fileds like: firstName, lastName, zipCode, refreshToken etc. 
When trying to update just a value of refreshToken i use 'updateData' like shown in documentation docs 
my code:
    static func updateToken(token:String){

Firestore.firestore().collection("companies").document(self.user.companyId).collection("employees")
    .document(self.user.employeeId).updateData(["refreshToken" : token])
}

but that removees all other values of employee document (firstName, lastName, zipCode etc) and just new value of refreshToken exist in the node after operation. Am I doing something worng or I missunderstod idea of "updateData"?

A:

If you want to update the value of a field and if the document does exist, its contents will be overwritten with the newly provided data, unless you specify that the data should be merged into the existing document, as follows:
Firestore.firestore().collection("companies").document(self.user.companyId)
    .collection("employees").document(self.user.employeeId)
    .setData(["refreshToken" : token], merge: true)
}

See, I have usef setData() function instead of updateData().

