Answers for "firestore read data"

8

firestore get all documents in collection

// retrieve a collection
db.collection('documents')
  .get()
  .then(querySnapshot => {
    const documents = querySnapshot.docs.map(doc => doc.data())
    // do something with documents
  })

// retrieve a document
db.collection('documents')
  .doc(documentId)
  .get()
  .then(snapshot => {
    const document = snapshot.data()
    // do something with document
  })
Posted by: Guest on December-29-2020
1

read data firestore java

DocumentReference docRef = db.collection("cities").document("SF");
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
    @Override
    public void onComplete(@NonNull Task<DocumentSnapshot> task) {
        if (task.isSuccessful()) {
            DocumentSnapshot document = task.getResult();
            if (document.exists()) {
                Log.d(TAG, "DocumentSnapshot data: " + document.getData());
            } else {
                Log.d(TAG, "No such document");
            }
        } else {
            Log.d(TAG, "get failed with ", task.getException());
        }
    }
});
Posted by: Guest on September-11-2021
4

get data in from a collection firestore

db.collection("users").get().then((querySnapshot) => {
    querySnapshot.forEach((doc) => {
        console.log(`${doc.id} => ${doc.data()}`);
    });
Posted by: Guest on December-11-2020
0

collection get firesotre

async getMarker() {
    const snapshot = await firebase.firestore().collection('events').get()
    return snapshot.docs.map(doc => doc.data());
}
Posted by: Guest on December-28-2020
2

get one document based on id in firestore

//retrieve one document and save it to userDetails
const [userDetails, setUserDetails] = useState('')
db.collection('users').doc(id).get()
        .then(snapshot => setUserDetails(snapshot.data()))
Posted by: Guest on June-28-2020
0

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)
        })
    },[])
Posted by: Guest on June-28-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language