get datas cloud firestore code example

Example 1: get data from firestore

const [hospitalsDetails, setHospitalsDetails] = useState([])
    useEffect(()=>{
        //load hospitals into hospitalsList
        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");// Atomically add a new region to the "regions" array field.washingtonRef.update({    regions: firebase.firestore.FieldValue.arrayUnion("greater_virginia")});// Atomically remove a region from the "regions" array field.washingtonRef.update({    regions: firebase.firestore.FieldValue.arrayRemove("east_coast")});