我想用React Native Firebase创建子集合,以创建这样的火库结构:
groups
->group
->scheduledQuestionnaires
->questionnaire (fields: id, type and timestamp)
users
->user
->groups
(fields: id and name)
我已经创建了集合groups
和users
,但如何以编程方式为每个组创建子集合scheduledQuestionnaires
呢。
我可以很好地将带有字段的文档添加到集合中,但似乎找不到创建(子(集合的方法。我是走错了路还是错过了什么?
编辑添加到monsty的答案中。以下是我想做的事情的代码片段:
firestore()
.collection('groups')
.doc('group1/scheduledQuestionnaires/questionnaire1')
.set({
id: '1',
type: 'type',
timestamp: 'timestamp',
});
您不需要为每个集合创建子集合,因为Firebase会处理它。
如果您试图将文档保存到"/groups/group/schelledQuestionnaires/hello/world/my_document"中,Firebase将创建所需的所有子集合(在本例中为:hello和world(。