【发布时间】:2021-07-08 06:01:22
【问题描述】:
我想创建一个嵌套集合,因为我想存储比文档地图所能包含的更多的字段。我的文档名称已定义,以便我可以在基于名称的路径上获取数据。所以我不想创建一个动态名称。由于名称有限,并且这些字段下可能有很多字段,我认为集合是更好的选择。
如果没有数据集父文档,嵌套集合将不会创建。设置数据对我来说似乎没有必要。但我想设置创建日期。并在该文档上添加集合。但似乎我无法在一个定义的路径中创建所有这些。代码会解释更多:
val db = Firebase.firestore
val where = "Denvar"
val what = "WalkingOrRunning"
val docData = hashMapOf(
"date" to Timestamp(Date()),
"duration" to "10 min"
"comment" to "Dummy comment"
)
//document who got fields like name, UsersActivity got doc Start date previously set.
val userPath = db.collection("Users").document(who)
.collection("UsersActivity").document("history").set(docData) // want to continue next line here but that will create empty document thus collection will not save so adding dummy fields
userPath.collection(what).document(where).set(docData) // this does not create collection either
那么您对我的数据结构有何建议?
【问题讨论】:
标签: android firebase kotlin google-cloud-firestore