It's unclear from your question if you expect the name to be unique or if there are many users named "kavin".
But assuming that the user's name is unique, you might solve it like this
self.DBRef.collection("users")
.whereField("name", isEqualTo: "kavin")
.getDocuments() { (querySnapshot, err) in
if let err = err {
// Some error occured
} else if querySnapshot!.documents.count != 1 {
// Perhaps this is an error for you?
} else {
let document = querySnapshot!.documents.first
document.reference.updateData([
"age": 99
])
}
}
You have to make an asynchronous query that will return a QuerySnapshot which has an array of documents as a result. The resulting query does not have any concept of "unique" fields on your documents. So you must handle the logic of what it means if you get more than one result when the name is supposed to be unique.
Once you have retrieved a query result you can directly access a reference to that document with the reference attribute and update the fields that you wanted.