Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To create a collection within a collection in a Flutter document, you can follow these steps:

  1. Create a reference to the parent document:
final DocumentReference parentDocRef = Firestore.instance.collection('parentCollection').document('parentDocId');
  1. Use the parent document reference to create a reference to the child collection:
final CollectionReference childCollectionRef = parentDocRef.collection('childCollection');
  1. Add a new document in the child collection:
childCollectionRef.add({'field1': 'value1', 'field2': 'value2'});
  1. You can also retrieve documents from the child collection:
childCollectionRef.getDocuments().then((QuerySnapshot snapshot) {
  snapshot.documents.forEach((DocumentSnapshot document) {
    // process document data
  });
});