使用 Flutter 在 Cloud Firestore 中创建文档

用户3702643

我在处理一个问题时遇到了很多困难。

在 flutter 上使用 cloud_firestore,如何在集合中创建一个新文档(如果它不存在),在该集合中创建一个新文档并在该文档中创建一个具有名称、bool 类型和值的新字段真的?

这就是我现在所拥有的:

  await Firestore.instance
      .collection(collectionName)
      .document(documentName)
      .get()
      .then((DocumentSnapshot ds) {
         // do something here

  });

谢谢你。

彼得·哈达德

要创建新文档,您需要使用add()

  Firestore.instance.collection("users").add(
  {
    "name"    : "peter",
    "boolVal" : true
  }).then((value){
    print(value.documentID);
  });

add()将创建一个带有随机 id 的文档,如果您想使用自己的 id 则使用setData()

  Firestore.instance.collection("users").document(id).setData(
  {
    "name" : "peter",
    "boolVal" : true
  }).then((value){
    print(value.documentID);
  })

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用Flutter在FireStore中的集合中创建文档

如何使用Flutter监听Cloud Firestore中的文档更改?

如何使用flutter从Cloud Firestore中删除特定文档?

在flutter中从cloud_firestore删除文档

在Flutter中获取Cloud Firestore文档的路径

使用云功能在Firestore中创建文档

使用 Apple 登录时无法在 Firestore 中创建文档

如何使用Flutter在Firestore中的uid文档中创建集合?

从Flutter中的Firestore查询单个文档(cloud_firestore插件)

如何使用Dart / Flutter在Cloud Firestore中存储简单矩阵?

无法使用 Cloud Firestore 和 Flutter 在 ListView 中获取

Flutter:如何使用cloud_firestore从文档中收集数据?

Cloud Firestore查询以获取文档ID,Flutter

Flutter-从Cloud Firestore中的文档中删除特定字段?

在Flutter Cloud Firestore中设置自定义文档ID

Flutter中Cloud Firestore的FieldValue.increment

如何使用 flutter cloud_firestore 插件从 DocumentID 获取文档引用

如何在flutter中使用cloud firestore发布期间获取当前自动生成的文档ID?

无法获取有关在 flutter firebase (cloud firestore) 中使用 where in 的文档

Flutter和Cloud Firestore

在Firestore中创建对Cloud Storage文档的引用

如何使用 Flutter 为 Cloud Firestore 创建具有嵌套地图字段的用户模型?

如何使用文档 ID cloud firestore 为查询创建索引

如何使用graphql从Firebase使用flutter从Cloud Firestore获取数据?

如何使用Google Cloud Function在Firestore上创建的文档中添加新值

使用 Flutter 创建用户集合后,如何在 Firestore 中检索文档 ID

如何在Flutter中为网络和Android使用cloud_firestore?

为什么Flutter中传递的数据返回null?我使用 Cloud Firestore 作为我的数据存储

如何使用 Flutter 在具有数据类型的 Firebase Cloud Firestore 中写入数据