Answers for "firebase read data firestore"

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
2

get data from firebase firestore

useEffect(() => {
	db.collection('posts')
      .orderBy('timestamp', 'asc') // optional
      .onSnapshot((snapshot) => {
		setPosts(
			snapshot.docs.map((doc) => {
				return doc.data();
			})
		);
	});
}, []);
Posted by: Guest on June-15-2021

Code answers related to "firebase read data firestore"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language