在 Firestore 中自动创建集合
Posted
技术标签:
【中文标题】在 Firestore 中自动创建集合【英文标题】:Automatically create collection in firestore 【发布时间】:2020-12-14 05:57:17 【问题描述】:是否可以更新此方法:
void uploadMatch(team1, team2)
Firestore.instance.collection("upcomings").add(
"createdAt": Timestamp.now(),
"upcomingTeam1": team1,
"upcomingTeam2": team2
);
所以如果即将到来的集合不存在,它会创建它吗?谢谢!
【问题讨论】:
【参考方案1】:来自documentation:
集合和文档是在 Cloud Firestore 中隐式创建的。 只需将数据分配给集合中的文档。如果要么 集合或文档不存在,Cloud Firestore 会创建它。
所以回答你的问题:这是不可能的! 集合是隐式创建的,当您创建文档时,当您删除集合中的最后一个文档时,它将不复存在。
【讨论】:
以上是关于在 Firestore 中自动创建集合的主要内容,如果未能解决你的问题,请参考以下文章
Flutter:使用来自 Firestore 的多集合流创建动态更新的 DataTable
扑。创建 Firestore 文档和集合的 List<String>