The getDocuments
callback gets called with two values (querySnapshot
and `error), only one of which will have a value.
You're ignoring the error
and assuming that querySnapshot
has a value, which not only leads to the error you get, but also hides the likely cause.
I recommend following the pattern used in this example from the Firestore documentation on getting documents:
db.collection("cities").whereField("capital", isEqualTo: true)
.getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: (err)")
} else {
for document in querySnapshot!.documents {
print("(document.documentID) => (document.data())")
}
}
}
By logging the error
you can see what went wrong with your getDocuments()
call.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…