I'm trying to get data from a nested collection. When I create an appointment - I'm saving the appointmentId and doctorId in the current user. When I need them I take them from the user. And there is the big question - I creating appointments in firestore like this - appointments - [doctorId] (1) - currentDoctorApp - appointmentId - data part1 | part2. I know I can add data like normal - appointments - autoId - data, but I want to separate them, for a better search I think?
(1) - because I think if I have 50 doctors and the current user has appointmenthours at only 2, I will search in these 2 fields, not in all 50
This is the way I add it to appointments collection, but how can I get it? Еspecially when I get more than 1 doctorId. First I have to query by document id. I hope it's not very confusing
try {
await setDoc(doc(db, `appointments/${params.doctorId}`, 'currentDoctorApp', generatedId), {
doctorId: params.doctorId,
userId: currentUser.uid,
date: date,
hour: hour,
status: 'active',
address: doctorData.hospitalAddres,
hospital: doctorData.hospitalName
});
await updateDoc(doc(db, 'users', currentUser.uid), {
appointments: arrayUnion({
appointmentId: generatedId,
doctorId: params.doctorId,
})
});
} catch (error) {
console.log(error);
}



appointmentscollection from the user and also get all its subcollection. What specific data do you want to get? Could you please also include the data structure you want to achieve in your question for us to better understand what you want to get. Have you tried any query to get the data you want? If so, could you also please include it on your question.current user, which ids are the same as one of thedoctors-idand one of theappointment-idin the database. Every appointment for the current doctor is saved in appointments collection with his id.https://prnt.sc/Lgu_OHhTcd5Yandhttps://prnt.sc/foumHrevx9lV. I want to get the data from the appointments