Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically create collection in firestore

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!

like image 326
Bennett567 Avatar asked Dec 14 '25 04:12

Bennett567


1 Answers

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.

like image 84
alvaro fvr Avatar answered Dec 16 '25 21:12

alvaro fvr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!