flutter - Flutter Firebase 如何创建新集合?
问题描述
如何在我的 Firebase Cloud Firestore 中创建一个新集合,并在我的服务文件中使用 dart 和 flutter 函数创建一个新集合?我搜索了它,但我只能找到如何将数据添加到 firebase 中的现有集合。有人能帮我吗?请:)
解决方案
来自 Cloud Firestore 文档(此处):
Cloud Firestore 将数据存储在 Documents 中,这些 Documents 存储在 Collections 中。Cloud Firestore 会在您首次向文档添加数据时隐式创建集合和文档。您不需要显式创建集合或文档。
因此,您需要做的是添加到以下集合中,您的集合将被创建:
Firestore.instance.collection("you_Collection_Path").add({
"key":value //your data which will be added to the collection and collection will be created after this
}).then((_){
print("collection created");
}).catchError((_){
print("an error occured");
});
推荐阅读
- vue.js - 如何在 Vue.js 中保存 url 并使用 chrome api 进行 chrome 扩展?
- c++ - 如何使 callgrind 的结果具有人类可读性
- sql - 返回不同行的条件 SQL Where 子句
- single-sign-on - 在 ASP.NET 中为 SSO 构建安全令牌服务 (STS) 应用程序
- java - 使用 Java.io.file,当我尝试从中读取证书时,它总是指向错误的路径
- java - Hibernate Search:如何动态配置 JPA 实体的索引?
- webrtc - 检查webrtc连接是否建立成功
- reactjs - 当我在 gatsby-confis.js 文件中添加 gatsby-plugin-sass
- c# - Sql Tree错误中重新实现OrderBy、ThenBy和Null TypeMapping
- mysql - MySQL - 如何将两个日期之间的天数作为年份?