get datas cloud firestore code example
Example 1: get data from firestore
const [hospitalsDetails, setHospitalsDetails] = useState([])
useEffect(()=>{
const hospitals = []
db.collection('Hospitals').get()
.then(snapshot => {
snapshot.docs.forEach(hospital => {
let currentID = hospital.id
let appObj = { ...hospital.data(), ['id']: currentID }
hospitals.push(appObj)
hospitals.push(hospital.data())
})
setHospitalsDetails(hospitals)
})
},[])
Example 2: document.set() firebasefirestore java
var washingtonRef = db.collection("cities").doc("DC");