Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore: create subcollection from iOS SDK

Is it possible to create a subcollection within a document by using iOS SDK? I can't find any appropriate method on API and documentation doesn't provide any guides.

like image 729
Andrey Arzhannikov Avatar asked Dec 04 '25 18:12

Andrey Arzhannikov


1 Answers

As a general rule, you don't explicitly "create" collections. Instead, you create documents and, if you've specified them as belonging to a collection that does not yet exist, then that collection will be created along the way.

So if you have a /users/jane document and want to add a history subcollection, you basically do this by creating the first document you want to appear in that subcollection -- i.e. something like:

Firestore.firestore().collection("users/jane/history").addDocument(historyData)

I believe this would work, too:

Firestore.firestore().document("users/jane/history/20171105")setData(historyData)
like image 134
Todd Kerpelman Avatar answered Dec 06 '25 06:12

Todd Kerpelman



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!