迭代云Firestore(Firebase)中的子级

迭代云Firestore(Firebase)中的子级,firebase,kotlin,google-cloud-firestore,Firebase,Kotlin,Google Cloud Firestore,我正在尝试从实时数据库迁移到firebase中的云firestore。我在重新编写代码时遇到了一些问题,这些代码会在数据库中的子对象上进行迭代 我的旧代码如下所示: if (dataSnapshot.exists()) { for (x in dataSnapshot.children) { FetchInformation(x.key) }

我正在尝试从实时数据库迁移到firebase中的云firestore。我在重新编写代码时遇到了一些问题,这些代码会在数据库中的子对象上进行迭代

我的旧代码如下所示:

                if (dataSnapshot.exists()) {
                for (x in dataSnapshot.children) {
                    FetchInformation(x.key)
                }
            }
            if (snapshot!!.exists()) {

            for (x in snapshot){
                FetchInformation(x.key)
            }


        } else {
            Log.d(TAG, "Current data: null")
        }
对于Firestore,它看起来是这样的:

                if (dataSnapshot.exists()) {
                for (x in dataSnapshot.children) {
                    FetchInformation(x.key)
                }
            }
            if (snapshot!!.exists()) {

            for (x in snapshot){
                FetchInformation(x.key)
            }


        } else {
            Log.d(TAG, "Current data: null")
        }
然而,firestore中不存在类似snapshot.children的东西,我收到了编译错误

'For循环范围必须有一个'iterator()'方法

你可以试试

for(i in 0..snapshot) {
    // x..y is the range [x, y]
}


请将Firebase实时数据库结构添加为JSON文件或至少是屏幕截图。还请添加Firestore数据库结构作为屏幕截图。