Skip to content

Instantly share code, notes, and snippets.

@hiranya911
Last active March 1, 2020 23:35
Show Gist options
  • Save hiranya911/6c1546f20962c246ef601b143e421fa0 to your computer and use it in GitHub Desktop.
Save hiranya911/6c1546f20962c246ef601b143e421fa0 to your computer and use it in GitHub Desktop.
// Latest security rules look for a `familyName` field instead of `surname`. This
// function will not therefore work.
fun addPerson(firstName: String, surname: String): Task<Void> {
val data = hashMapOf(
"firstName" to firstName,
"surname" to surname
)
return db.collection("people").document()
.set(data)
}
// New documents doesn't have a `surname` field. The assertion will fail for
// those documents.
fun getPerson(personId: String) {
db.collection("people").document(personId)
.get()
.addOnSuccessListener { snapshot ->
val data = snapshot.data ?: hashMapOf()
val surname = data["surname"]
assert(surname is String)
updateView(surname)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment