【问题标题】:How to get more the tow subcollections from a rootcollection如何从根集合中获取更多的两个子集合
【发布时间】:2019-12-27 22:31:13
【问题描述】:

我的数据库结构是这样的:

|- 服务(根集合)
|---- 文档1
|-------- 评论(子集 1)
|------------- subdoc1
|------------- subdoc2 ...
|-------- 查询(子集2)
|------------- subdoc1 ...

我的根集合(服务)有两个子集合。
我想得到他所有子集合的根集合。

我正在使用 react-redux-firebase 和 redux-firestore,并使用 firestoreConnect 连接到我的数据库。

我的代码是这样的:

firestoreConnect((props) => [    
    { collection: 'services', doc: props.match.params.id },
    { collection: 'services', doc: props.match.params.id, subcollections: [{ collection: 'inquiry' }]},
    { collection: 'services', doc: props.match.params.id, subcollections: [{ collection: 'reviews' }]}
  ]), 


我的预期:我将“state.firestore.ordered”中的所有数据作为数组。
但总是最后一个查询数据(= subcollections : [{ collection: 'reviews' }]) 被重写在 'ordered' 区域。结果总是在那里只有一个子集合。

所以我只想问'如何使用 firestoreConnect 获得 2 个以上的子集合'?
我希望有人给我一些提示我做错了什么和误解!
非常感谢:)

【问题讨论】:

  • 你想一次性得到他所有子集合的根集合吗?

标签: react-redux google-cloud-firestore react-redux-firebase


【解决方案1】:

像下面这样检索它。

let rootRef = db.collection('rootCollection').doc('docId');
   rootRef .getCollections().then(collections => {
   collections.forEach(collection => {
   console.log('Subcollection id:', collection.id);
  });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多