Skip to content Skip to sidebar Skip to footer

Get Field From Firestore Document

Is it possible to extract and parse just a single field from a Firestore object without running a For Each or alternatively first passing this to an array? Specifically, I have pul

Solution 1:

Is it possible to extract and parse just a single field from a Firestore object without running a For Each

Yes, it is possible. According to the official documentation, you can achieve this using DocumentSnapshot's get() function:

Retrieves the field specified by fieldPath. Returns undefined if the document or field doesn't exist.

In code, should look like this:

docRef.get().then(function(doc) {
    if (doc.exists) {
        console.log("profileId: ", doc.get("profileId"));
    } else {
        console.log("No such document!");
    }
}).catch(function(error) {
    console.log("Error getting document:", error);
});

Post a Comment for "Get Field From Firestore Document"