简体   繁体   中英

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.

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',
          });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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