Is this a limitation to Firebase or am I doing this all wrong? Everything works until I add the db.collection('users').doc(friendId).get()...
in the middle of the code. Thanks in advance.
const db = admin.firestore();
const friendRef = db.collection('users').doc(id).collection('friends');
friendsList = [];
friendRef.get().then((onSnapshot) => {
if (!onSnapshot.empty) {
onSnapshot.forEach((friend) => {
const friendId = String(friend.data().person_id);
db.collection('users').doc(friendId).get().then((result) => {
const firstName = String(result.data().name.first);
const lastName = String(result.data().name.last);
})
const data = {
personId: friendId,
firstName: firstName,
lastName: lastName,
}
friendsList.push(data);
})
res.send(friendsList);
} else {
res.send({
'message': 'no friends'
});
}
}).catch((e) => {
res.send({
'error': e
});
})