【问题标题】:How to retrieve a specific field information in a database?如何检索数据库中的特定字段信息?
【发布时间】:2020-10-12 05:58:24
【问题描述】:

我创建了以下数据库:

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
});

如何访问“active-temp”字段?

【问题讨论】:

    标签: javascript database firebase google-cloud-firestore


    【解决方案1】:

    要检索active-temp,请执行以下操作:

    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() 将包含所有数据

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-20
      • 2015-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多