如何将 firestoreConnect 指向 React-Redux-Firebase 中的嵌套 collection?

How to point firestoreConnect to a nested collection in React-Redux-Firebase?

下面的行将 firestoreConnect 指向我的 collection 标记为 projects

 { collection: 'projects' }

当项目 collection 像这样直接位于根目录下时有效:

root/
  projects/

但是,如果项目 collection 被一个本身在另一个 collection 中的文档引用,比如说,像这样:

root/
  users/
    alice/
      projects/

如何将 firestoreConnect 指向 projects collection?

The documentation is silent on the matter.

Link to video
import React, { Component } from 'react'
import ProjectList from '../projects/ProjectList'
import Notifications from './Notifications'
import { connect } from 'react-redux'
import { firestoreConnect } from 'react-redux-firebase'
import { compose } from 'redux'
import { Redirect } from 'react-router-dom'

class Dashboard extends Component {...}

const mapStateToProps = (state) => {
  // console.log(state);
  return {
    projects: state.firestore.ordered.projects,
    auth: state.firebase.auth,
  }
}

export default compose(
  connect(mapStateToProps),
  firestoreConnect([
    { collection: 'projects' }, // <-- Question is about this line
  ])
)(Dashboard)

编辑:尝试失败

From what I can piece together from the comments here 看起来答案可能是:

firestoreConnect([
  { 
    collection : 'users',
    doc        : 'alice',
    collection : 'projects',
  }
])

但是那个尝试失败了。

可以通过将多个 collection/doc 设置传递给 subcollections 参数来完成,如下所示:

firestoreConnect(() => [
  {
    collection: 'states',
    doc: 'CA',
    subcollections: [
      { collection: 'cities', doc: 'SF' },
      { collection: 'zips' }
    ]
  }
])

这在 firestoreConnect section of the react-redux-firebase docs (since it is a react specific HOC). The options that can be passed to queries are documented in the README of redux-firestore 中有注明。

如果你正在做嵌套的子集合,你可能会想要使用 v1.*.* 版本,因为子集合在 redux 状态下与顶级集合一起存储。请注意,新版本有一个 different API , as described in the v1.0.0 roadmap.

披露:我是 redux-firestore 的作者