Reputation: 15462
I am looking to create subcollections with React Native Firebase to create a firestore structure like this:
groups
->group
->scheduledQuestionnaires
->questionnaire (fields: id, type and timestamp)
users
->user
->groups
(fields: id and name)
I have created the collections groups
and users
, but how can I create a subcollection scheduledQuestionnaires
for every group programmatically.
I am able to add documents with fields to collections just fine, but I can't seem to find a way to create (sub)collections. Am I going the wrong way about it or am I missing something?
EDIT To add to the answer by monsty. Here is a code snippet of what I wanted to do:
firestore()
.collection('groups')
.doc('group1/scheduledQuestionnaires/questionnaire1')
.set({
id: '1',
type: 'type',
timestamp: 'timestamp',
});
Upvotes: 1
Views: 1145
Reputation: 633
You don't need to create subcollections for every collection, because Firebase will handle it.
If you try to save a document into "/groups/group/scheduledQuestionnaires/hello/world/my_document", Firebase will create all the sub collections needed (in this case : hello and world).
Upvotes: 2