I'm trying to retrieve a firestore firebase subcollection.
With this code below everything is ok:
await firestore()
.collection('VILLES')
.doc('9HNkAv99pd1rm9Q3vdwd')
.collection('restaurents')
.get()
.then(querySnapshot => {
querySnapshot.forEach(doc => {
const {image, address, description, title, ratings, contact} =
doc.data();
list.push({
id: doc.id,
image: image,
address: address,
description: description,
title: title,
ratings: ratings,
contact: contact,
});
});
});
setrestaurents(list);
if (loading) {
setloading(false);
}
console.log('restaurents:', restaurents);
} catch (e) {
console.log(e);
}
But the problem is I have many documents which have a personal collection how can I write a code so that every document will retrieve his own subcollection, and I know the problem is around the document Id
I tried this
await firestore()
.collection('VILLES')
.doc(VILLESId)
.collection('restaurents')
.get()
but I'm getting this error
Possible Unhandled Promise Rejection (id: 0):
TypeError: undefined is not an object (evaluating '_ref2.VILLESId')