【问题标题】:Firestore Firebase make Query by documentID, swiftFirestore Firebase 通过 documentID 快速进行查询
【发布时间】:2020-03-08 11:48:56
【问题描述】:

所以我有一个名为 users 的集合。 我希望能够搜索用户是否存在,如果存在则显示其文档。

我尝试了 2 个选项,但似乎都不起作用

  db.collection("users").whereField(DocumentID == "max")
            .getDocuments()

第二种方式

db.collection("users").whereField("Max", isEqualTo: true)
            .getDocuments()

please find image of my database attached here

【问题讨论】:

    标签: swift firebase google-cloud-firestore


    【解决方案1】:

    试试这个:

    let db = Firestore.firestore()
    
    let docRef = db.collection("collectionName").document("documentName")
    
    docRef.getDocument { (document, error) in
        if let document = document, document.exists {
            let password = document.get("fieldName")
        } else {
            print("Document does not exist")
        }
    }
    

    编辑:查看您的代码,我认为您混淆了集合、文档和字段。

    您的情况下的集合是“用户”,文档是您图像中的第二列,例如。 Arthur、Fredrick 等。在 Arthur 的文档中,有一个字段:密码。所以它是集合→文档→字段。

    【讨论】:

    • 就像一个魅力。非常感谢....这是我正在寻找的行“如果让文档=文档,文档存在”
    猜你喜欢
    • 2018-05-23
    • 1970-01-01
    • 2019-10-02
    • 2015-09-13
    • 2018-07-25
    • 1970-01-01
    • 2017-06-13
    • 2020-11-22
    • 1970-01-01
    相关资源
    最近更新 更多