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()
,每个调用都包含要放入文档中的数据