简体   繁体   English

如何判断我的值是否已存在于 Firebase Firestore 中?

[英]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.

相关问题 我如何判断它是图像还是视频 - Firebase Storage/Firestore - How can I tell if it's an image or video - Firebase Storage/Firestore 如何检查 Cloud Firestore 中任何文档的集合中是否存在值(例如名称)? - How can I check if a value e.g. name exists in a collection within any of documents in Cloud Firestore? Firebase Firestore iOS:如何将图像保存到 Firestore 中的集合中? - Firebase Firestore iOS: How can I save images to a collection in the firestore? 如何在 Firebase Firestore 上获取一个字段? - How can I get one field on Firebase Firestore? 如何检查 Firebase/Firestore 中的其他集合中是否存在值 - How to check if value exists in other collection in Firebase/Firestore 如何使用 Firebase Firestore 获取悲观锁? - How can I use Firebase Firestore to acquire a pessimistic lock? 在 firebase firestore 中,如何在不覆盖子集合的情况下更新文档? - in firebase firestore how can I update a document without overwriting subcollections? 如何按顺序显示 Firebase Firestore 数据? - How can I display Firebase Firestore data in order? 如何从 Firebase Firestore 获取 ReactJs 的数据? - How Can I get data with ReactJs from Firebase Firestore? 我如何在 flutter 和 firebase firestore 中制作价格范围过滤器 - How can i make price range filter in flutter and firebase firestore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM