Trying to read all sub collections from a document inside a root-level collection from firebase's Firestore in a react-native project. Not too sure which documentation to follow (web-can't do getCollections()
/node?). Firebase is imported and I have successfully retrieved other data from firestore, but never have I been able to read sub collection data. This is not using the library react-native-firebase
(Although I’ve tried with react-native-firebase and it has no documented solution to this either) Regardless, I've tried:
componentDidMount() {
firebase
.firestore()
.collection('users')
.doc(this.props.user.uid)
.getCollections('conversations')
.then(collections => {
collections.forEach(collection => {
alert(collection.id)
})
})
}
the above returns '_firebase.default.firestore().collection("users").doc(this.props.user.uid).getCollections' is undefined
also have tried:
componentDidMount() {
firebase
.firestore()
.collection("users")
.doc(this.props.user.uid)
.collection("conversations")
.get()
.then(collections => {
collections.forEach(collection => {
alert(JSON.stringify(collection)); //collection.id is can be read here
});
});
in the above, the collection id can be read, but how can the document fields be read? the above gives me cyclic structure errors.
alert(collection.data())
gives me [object Object]
alert(JSON.stringify(collection.data())
gives me cyclic structure errors
here is the firestore:
The practical application would be populating all conversations for a given user, and then all messages for a given conversation. How Do I read data from all sub collections from Firestore in a react-native project?