Firebase从快照中获取一些数据

时间:2017-12-10 15:53:07

标签: javascript firebase firebase-realtime-database firebase-authentication google-cloud-functions

{
  "OrnekUserId": {
    "AccessToken": "asd",
    "CreatedAt": "2017/12/10",
    "DeletedAt": -1,
    "Email": "deneme@deneme.com",
    "FirstName": "deneme",
    "LastName": "denemeSoyad",
    "LoginType": 0,
    "Phone": "",
    "ThumbNailUrl": "",
    "UpdatedAt": -1,
    "UserName": "denemeName"
  }
}

enter image description here

我通过搜索电子邮件得到这个json数据,最后我得到了这个,但是你看到另一个问题'阿里'这是我的用户ID列,每个人都会更改。

我试图获取用户名和用户ID(' ali')列值,但我不能这样做。

这是我的代码

exports.ForgotPassword = functions.https.onRequest((req,res) => {
    const email = req.query.Email;
    if (email == "" || email == null) {
        return res.json({
            result: "E-mail can not be null"
        })
    } else {
        const ref = admin.database().ref('Users').orderByChild('Email').equalTo(email).once('value', snapshot => {
            if (snapshot.val() == null) {
                return res.json({
                    response: false
                })
            } else {
                return res.json({
                    response: snapshot.val()
                })

            }
        })
    }
})

在最后的其他状态,我需要得到" UserName":" asdada"和"阿里"

我该怎么做?

1 个答案:

答案 0 :(得分:0)

我不确定,但他可能会给出结果:

exports.ForgotPassword = functions.https.onRequest((req,res) => {
    const email = req.query.Email;
    if (email == "" || email == null) {
        return res.json({
            result: "E-mail can not be null"
        })
    } else {
        return admin.database().ref('Users').orderByChild('Email').equalTo(email).once('value', snapshot => {
            if (snapshot.exists()) {
                return res.send(snapshot.val());   
            } 
        })
    }
})