简体   繁体   English

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

[英]How to create a collection inside a document in Firestore with Flutter?

I'm working with a document and I want to create an empty collection inside the document.我正在处理一个文档,我想在文档中创建一个空集合。

FirebaseFirestore.instance.collection('Users').doc("thisdoc). ??? (create collection inside this document)

I don't know what to add instead of???我不知道要添加什么而不是???

The documentation will help you there.文档将为您提供帮助。

NOTE The Firebase team is migrating these docs onto firebase.com directly, so this link may get old quickly in the next months.注意Firebase 团队正在将这些文档直接迁移到 firebase.com 上,因此此链接在接下来的几个月中可能会很快失效。

EDIT.编辑。 Since you need to create it under a subcollection, simply:由于您需要在子集合下创建它,因此只需:

  1. Take a reference of that document参考该文件
  2. Reference a subcollection in that document, even if it doesn't exist, yet引用该文档中的子集合,即使它不存在,但
  3. Create a first document in there, and your subcollection is made.在其中创建第一个文档,然后创建您的子集合。

Pseudocode:伪代码:

// WARN, PSEUDOCODE AHEAD

final documentRef = firestore.collection("myCol").document("myDoc");
final subCollectRef = documentRef.collection("mySubCol");

subCollectRef.add({
            'your': 'data',
          });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM