I am not able to get the sub-collection from my Firestore data.
I followed the documentation here. And also looked at many other similar question on this.
I can't seem to get the array of data that i want to get.
import "../../styles/projects/ProjectDashboard.css";
import ProjectList from "./ProjectList";
import { connect } from "react-redux";
import { firestoreConnect } from "react-redux-firebase";
import { compose } from "redux";
import { Redirect } from "react-router-dom";
export class ProjectDashboard extends Component {
render() {
const { projects, auth } = this.props;
if (!auth.uid) return <Redirect to="/sigin" />;
return (
<div className="container">
<h2>Projects</h2>
<ProjectList projects={projects} />
</div>
);
}
}
const mapStateToProps = state => {
console.log(state);
return {
projects: state.firestore.ordered.projects,
auth: state.firebase.auth
};
};
export default compose(
connect(mapStateToProps),
firestoreConnect(props => {
return [
{
collection: "users",
doc: props.auth.uid,
subcollection: [{ collection: "projects" }]
}
];
})
)(ProjectDashboard);
this is what i am getting now from my console :
firestore:
|-composite: undefined
|-data: {users: {…}}
|-errors: {byQuery: {…}, allIds: Array(0)}
|-listeners: {byId: {…}, allIds: Array(1)}
|-ordered:
|--users: Array(1)
|---0: {id: "o06VEyRbGDcURTmKal3gDEDZQO73", firstName: "testing", lastName: "you", userId: "o06VEyRbGDcURTmKal3gDEDZQO73"}
|---length: 1
|---__proto__: Array(0)
|--__proto__: Object
|-queries: {}
|-status: {requesting: {…}, requested: {…}, timestamps: {…}}
|-__proto__: Object
I was thinking that my code will change this part:
|-ordered:
|--users: Array(1)
|---0: {id: "o06VEyRbGDcURTmKal3gDEDZQO73", firstName: "testing", lastName: "you", userId: "o06VEyRbGDcURTmKal3gDEDZQO73"}
to something like this:
|-ordered:
|--projects: Array(3)
|---0: {id: "o06VEyRbGDcURTmKal3gDEDZQO73", firstName: "testing", lastName: "you", userId: "o06VEyRbGDcURTmKal3gDEDZQO73"}
|---1: {id: "o06VEyRbGDcURTmKal3gDEDZQO73", firstName: "testing", lastName: "you", userId: "o06VEyRbGDcURTmKal3gDEDZQO73"}
|---2: {id: "o06VEyRbGDcURTmKal3gDEDZQO73", firstName: "testing", lastName: "you", userId: "o06VEyRbGDcURTmKal3gDEDZQO73"}
so i can get the array through the key. But now i am at a lost on how to change it into my sub-collection key.
I realised that it should be "subcollections" and not "subcollection"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With