簡體   English   中英

如何判斷我的值是否已存在於 Firebase Firestore 中?

[英]How can I tell if I value already exists in Firebase Firestore?

數據庫條目

我想收到一個bool ,讓我知道我的文檔是否有Wasiyyah ..

我試過的是: Firestore.firestore().collection(user..uid).document(docID):value(forKey: "Wasiyyah")

每次只會崩潰,所以這里一定有我不理解的地方。

沒有任何 function 來檢查文檔中是否存在字段。 您必須獲取文檔並檢查它是否存在:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM