Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 是否可以将嵌套的Kotlin类转换为Firestore中包含子集合的集合?_Firebase_Kotlin_Google Cloud Firestore - Fatal编程技术网

Firebase 是否可以将嵌套的Kotlin类转换为Firestore中包含子集合的集合?

Firebase 是否可以将嵌套的Kotlin类转换为Firestore中包含子集合的集合?,firebase,kotlin,google-cloud-firestore,Firebase,Kotlin,Google Cloud Firestore,有没有一个简单的方法来转换这样的东西 data class Pet ( val owner: Owner = Owner() ) data class Owner ( val name: String? = null, val email: String? = null ) 自动添加到Firestore集合 这对我不起作用: val owner = Owner("Joe", "test@test.com") val pet = Pet("Petty", owner)

有没有一个简单的方法来转换这样的东西

data class Pet (
    val owner: Owner = Owner()
)

data class Owner (
    val name: String? = null,
    val email: String? = null
)
自动添加到Firestore集合

这对我不起作用:

val owner = Owner("Joe", "test@test.com")
val pet = Pet("Petty", owner)

db.collection("pets").add(pet)

这是不可能的。当您
add()
对象时,它将转换为单个文档。如果需要创建多个文档,则还需要多次调用
add()
set()
,每个调用都包含要放入文档中的数据