I am building a system where users can follow a course. The users can follow a course and this then adds both courseID and userID into a members table. I am failing to then simply list the users information that are following this club (firstName, lastName etc.)
I manage to get the data and console log it but when I commit to my state, the state only shows one of the objects rather than an array which I can loop through.
I have the following collections:
Users: -> auto-id -> { firstName, LastName etc. }
Courses: -> auto-id -> { courseName, courseLocation etc. }
Members: -> auto-id -> { courseID, userID etc. }
Here is my action within my store:
state: {
members: []
},
mutations: {
SET_MEMBER_DETAIL(state, val) {
state.members = val
},
},
actions: {
retreiveMembers ({commit}, payload) {
db.collection('members')
.where('courseID', '==', payload.courseID)
.get()
.then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
const documents = doc.data()
db.collection('users')
.doc(documents.userID)
.get()
.then((res) => {
console.log(res.data())
commit('SET_MEMBER_DETAIL', res.data())
})
})
})
},
}
Here is the result in my console:
{admin: false, firstName: "Sam", lastName: "Staron"}
{admin: false, firstName: "Paul", lastName: "Staron"}
{admin: "Admin", firstName: "John", lastName: "Doe"}
When I view the state via vue chrome add on, I only receive the last array instead of all 3 and as an object.
members: Object
admin: "Admin"
firstName: "John"
lastName: "Doe"
I would like to commit the console logged results into my state as an array which i can then loop through on the front end.
Unless there is a more practical way to retrieve relational data with Firestore.
Thanking anyone in advance, Sam