获取Google Firestore中文档内的收藏ID

时间:2017-11-11 16:57:13

标签: swift firebase google-cloud-firestore

这是一份文件" TestAccount"它拥有2个系列。当我查询" TestAccount"有没有办法知道集合名称?文件?

enter image description here

这不会打印出集合名称:

db.collection("users").document("TestAccount").getDocument { (allDocs, allDocsErrors) in
        guard let _allDocs = allDocs,
            allDocs?.exists ?? false,
            allDocsErrors == nil else {
                print("early exit \(allDocs?.exists)") //always fires
                return
        }

1 个答案:

答案 0 :(得分:0)

结帐此代码,我从allDocs?.exists ?? false,allDocsErrors == nil条件列表中移除guard,这应该可以正常工作

db.collection("users").document("TestAccount").getDocument 
{ 
    (documentSnapshot, error) in

    guard let documentSnapshot = documentSnapshot else { 
        print("early exit \(documentSnapshot?.exists)");
        return
    }

    let children = documentSnapshot.data();
    for (id , value) in children 
    {
        print(id);
    }

}