0

I was wondering if you could create a sub-collection from within flutter to firestore. I've heard you need to add manually add a document or something like that before you can access a sub-collection from flutter, but I wanted to know if there was a work-around.

Something like this-> Firebase.Firestore.instance.collection('groups').doc(groupID).collection('posts').add('')

without having to manually add a document first. Thanks

1 Answers1

0

In Firestore (all client platforms, not just Flutter), both collections and subcollections don't "exist" in the console unless there is at least one document in it. If you want a subcollection to "exist", simply write a document to it.

When the last document is removed from a collection or subcollection, it ceases to "exist" in the console (after you reload it).

Collections are not really an "thing" in firestore. Documents are a thing, and they happen to be organized under collections. Your app should not depend on collections or subcollections existing - it should depends on documents being returned from queries on those collections.

See also:

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441