Automatically create collection in firestore

468

From the documentation:

Collections and documents are created implicitly in Cloud Firestore. Simply assign data to a document within a collection. If either the collection or document does not exist, Cloud Firestore creates it.

So to answer your question: It's not possible! The collection is created implicitly when you create a document and when you delete the last document in a collection, it will cease to exist.

Share:
468
Bennett567
Author by

Bennett567

I am a student mainly interested in flutter.

Updated on December 18, 2022

Comments

  • Bennett567
    Bennett567 over 1 year

    is it possible to update this method:

    void uploadMatch(team1, team2) {
        Firestore.instance.collection("upcomings").add({
          "createdAt": Timestamp.now(),
          "upcomingTeam1": team1,
          "upcomingTeam2": team2
        });
      }
    

    so that if the upcomings collection doesn't exist, it creates it? Thanks!