如何用React Native Firestore程序化创建子集?

问题描述 投票:0回答:1

我希望用React Native Firebase创建子集合,以创建一个像这样的firestore结构。

groups
   ->group
      ->scheduledQuestionnaires
         ->questionnaire (fields: id, type and timestamp)
users
   ->user
      ->groups
         (fields: id and name)

我已经创建了集合 groupsusers但我如何才能创建一个子库?scheduledQuestionnaires 为每个组编程。

我能够很好地将带有字段的文档添加到集合中,但我似乎找不到创建(子)集合的方法。是我走错了路还是我遗漏了什么?


EDIT补充一下monsty的回答。这是一个我想做的代码片段。

 firestore()
    .collection('groups')
    .doc('group1/scheduledQuestionnaires/questionnaire1')
    .set({
       id: '1',
       type: 'type',
       timestamp: 'timestamp',
    });
react-native react-native-firebase
1个回答
1
投票

你不需要为每个集合创建子集合,因为Firebase会处理它。

如果你试图将一个文档保存到 "groupgroupscheduledQuestionnaireshelloworldmy_document "中,Firebase将创建所有需要的子集合(在本例中:hello和world)。

© www.soinside.com 2019 - 2024. All rights reserved.