1// retrieve a collection
2db.collection('documents')
3 .get()
4 .then(querySnapshot => {
5 const documents = querySnapshot.docs.map(doc => doc.data())
6 // do something with documents
7 })
8
9// retrieve a document
10db.collection('documents')
11 .doc(documentId)
12 .get()
13 .then(snapshot => {
14 const document = snapshot.data()
15 // do something with document
16 })
1 db.collection("users").get().then((querySnapshot) => {
2 querySnapshot.forEach((doc) => {
3 console.log(`${doc.id} => ${doc.data()}`);
4 });
5
1async getMarker() {
2 const snapshot = await firebase.firestore().collection('events').get()
3 return snapshot.docs.map(doc => doc.data());
4}
1//retrieve one document and save it to userDetails
2const [userDetails, setUserDetails] = useState('')
3db.collection('users').doc(id).get()
4 .then(snapshot => setUserDetails(snapshot.data()))
1async getMarker() {
2 const snapshot = await firebase.firestore().collection('events').get()
3 return snapshot.docs.map(doc => doc.data());
4}
5
1const [hospitalsDetails, setHospitalsDetails] = useState([])
2 useEffect(()=>{
3 //load hospitals into hospitalsList
4 const hospitals = []
5 db.collection('Hospitals').get()
6 .then(snapshot => {
7 snapshot.docs.forEach(hospital => {
8 let currentID = hospital.id
9 let appObj = { ...hospital.data(), ['id']: currentID }
10 hospitals.push(appObj)
11
12 hospitals.push(hospital.data())
13 })
14 setHospitalsDetails(hospitals)
15 })
16 },[])
17