问题
Is there any way to add a document to firestore collection with custom id on Swift Language, not the id generated by firestore engine.
Thanks in advance for your responses.
回答1:
Yes. Just try this:
Firestore.firestore().collection("items").document("yourId").setData(["item": "test"])
回答2:
2020
Usually you'd want the error handling:
Firestore.firestore()
.collection("companyAddress")
.document(companyID)
.setData([
"address1": a1,
"address2": a2,
"city": c
]) { [weak self] err in
guard let self = self else { return }
if let err = err {
print("err ... \(err)")
self.yourErrorAlert()
}
else {
print("saved ok")
self.proceedWithUX()
}
}
来源:https://stackoverflow.com/questions/53583664/how-to-add-document-with-custom-id-to-firebase-firestore-on-swift