faccio
faccio

Reputation: 1034

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 ???

Upvotes: 0

Views: 787

Answers (1)

venir
venir

Reputation: 2096

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

Upvotes: 2

Related Questions