Reputation: 3579
I am fetching data from firestore and displaying those data's in a list.But the response which i am getting from firestore contains the document id separately and values separately. At the time of fetching itself i am combining it in a array. I would like to know whether it is the correct way of doing or is there any way we can do it better to combine the document id and values together.
Steps which i have done for combining:
db.getEmployees().then((snapshot) => {
let employee = [];
snapshot.docs.forEach((doc) => {
let user = doc.data();
user.id = doc.id;
employee.push(user);
});
dispatch(employeeUpdateSuccess(employee));
Upvotes: 0
Views: 401
Reputation: 83163
According to the documentation for a DocumentSnapshot
, there is no way to get the data and the id in a combined way (i.e. with only one method or via one property). In other words, you will always have to use the two following lines of code:
... = doc.data();
... = doc.id;
Upvotes: 3