有没有简单的方法来转换这样的东西
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()
,每个调用都带有要放入文档中的数据。
关于firebase - 是否可以在Firestore中将嵌套的Kotlin类转换为包含子集合的集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62398342/