Skip to content

Instantly share code, notes, and snippets.

@SUPERCILEX
Last active May 19, 2021 10:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SUPERCILEX/b0a15816a117dc109decad1bb30dd09e to your computer and use it in GitHub Desktop.
Save SUPERCILEX/b0a15816a117dc109decad1bb30dd09e to your computer and use it in GitHub Desktop.
fun Team.addScout() {
val scoutRef: DocumentReference = FirebaseFirestore.getInstance()
.collection("teams")
.document(id /* Field in Team */)
.collection("scouts")
.document() // Creating a document ref with a truly random id
scoutRef.set(Scout(scoutRef.id, templateId))
firestoreBatch {
val metricsRef = scoutRef.collection("metrics")
dataGatheredFromAQuery.forEach { metric ->
set(metricsRef.document(metric.id), metric)
}
}
}
inline fun firestoreBatch(transaction: WriteBatch.() -> Unit): Task<Void> = FirebaseFirestore.getInstance().batch().run {
transaction()
commit()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment