【问题标题】:Firebase get some data from snapshotFirebase 从快照中获取一些数据
【发布时间】:2017-12-10 15:53:07
【问题描述】:
{
  "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"
  }
}

我通过搜索电子邮件得到了这个 json 数据,最后我得到了这个,但是还有另一个问题,你看到 'ali' 这是我的用户 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()
                })

            }
        })
    }
})

在最后一个 else 状态我需要得到“UserName”:“asdada”和“ali”

我该怎么做?

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 阿比问题苏本örnekJSON daki VERI吉比她kullanıcıyıid'sialtındatutmayaçalışıyorumşimdimesela emaile戈尔aramayapıpkullanıcı智dönüyorAMA快照üzerindenkullanıcınınbilgilerineulaşamıyorummesela diyelimkullanıcınınIDSI 5şöyleyaparsamulaşırım快照。 val().5.UserName ama işte questionde tam burda ben oraya 5 yazamam her kullanıcının farklı id'si var nolur yardım et 4 saat oldu hala çözüm bulamadım :(
    • o kullanıcının id si snapshot.key , Bu işine yaramalı。 Yaramazsa daha açık yazarsan yardımcı olmaya çalışacağım。
    • abi snapshot.key koydum ama sadece Users yazıyor
    • 用户 tablom var hemen altında idler var her id'nin altındada o idye ait bilgiler var bilgiler sabit hepsinde aynı
    • Abi cozdum olayi value yerine child_added diyince direk idnin altindaki veriyi verdi dedigin gibi key getirince de idyi alabildim cok tesekkur ederim :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-10
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-16
    • 2023-04-10
    相关资源
    最近更新 更多