Manan Sharma
Manan Sharma

Reputation: 571

How to retrieve a specific field information in a database?

I have created the following database:

db.collection('users').doc(usercred.user.uid).set({
    "uid": usercred.user.uid,
    "phone": usercred.user.phoneNumber,
    "active-image-size-limit": 1500,
    "credits": 10,
    "active-temp": temName
});

How can I access the "active-temp" field in partuicular ?

Upvotes: 0

Views: 89

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80952

To retrieve active-temp do the following:

var docRef = db.collection("users").doc(usercred.user.uid);

docRef.get().then(function(doc) {
    if (doc.exists) {
        console.log(doc.data()["active-temp"]);
    } else {
        // doc.data() will be undefined in this case
        console.log("No such document!");
    }
}).catch(function(error) {
    console.log("Error getting document:", error);
});

doc.data() will contain all the data

Upvotes: 1

Related Questions