Russ
0
Q:

get data from firestore

//retrieve one document and save it to userDetails
const [userDetails, setUserDetails] = useState('')
db.collection('users').doc(id).get()
        .then(snapshot => setUserDetails(snapshot.data()))
1
const [userssDetails, setUserssDetails] = useState([])
    useEffect(()=>{
        //load hospitals into hospitalsList
        const users = []
        db.collection('users').get()
            .then(snapshot => {
                snapshot.docs.forEach(user => {
                    //add data to appObject with id and push them into users
                    let currentID = user.id
                    let appObj = { ...user.data(), ['id']: currentID }
                    users.push(appObj)
					//add data to users without the id from DB
                    users.push(user.data())
            })
           //save users to hospitalsDetails
            setUserssDetails(users)
        })
    },[])
-1
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)
        })
    },[])
0
var keys = [ 
  "-Ke1uhoT3gpHR_VsehIv",
  "-Ke8qAECkZC9ygGW3dEJ",
  "-Ke8qMU7OEfUnuXSlhhl"
];
var promises = keys.map(function(key) {
  return firebase.database().ref("/items/").child(key).once("value");
});
Promise.all(promises).then(function(snapshots) {
  snapshots.forEach(function(snapshot) {
    console.log(snapshot.key+": "+snapshot.val());
  });
});
0

New to Communities?

Join the community