[英]How can I tell if I value already exists in Firebase Firestore?
I would like to receive a bool
letting me know if my document has a Wasiyyah
or not..我想收到一个
bool
,让我知道我的文档是否有Wasiyyah
..
What I've tried: Firestore.firestore().collection(user..uid).document(docID):value(forKey: "Wasiyyah")
我试过的是:
Firestore.firestore().collection(user..uid).document(docID):value(forKey: "Wasiyyah")
Which only crashes every time, so there must be something I'm not understanding here.每次只会崩溃,所以这里一定有我不理解的地方。
There isn't any function to check if a field exists in a document.没有任何 function 来检查文档中是否存在字段。 You'll have to fetch the document and check for it's existence:
您必须获取文档并检查它是否存在:
let docRef = Firestore.firestore().collection(user!.uid).document(docID)
docRef.getDocument { (document, error) in
if let document = document, document.exists {
let data = document.data()
// Check if the field exists in data
} else {
print("Document does not exist")
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.