firebase实时DB,getValueAsync返回的值与DB不同

发布于 2025-02-10 07:22:30 字数 651 浏览 1 评论 0原文

我需要检索存储在Firebase实时DB中的值。到目前为止,它运行良好,但我发现一个错误,当您在一个设备上(移动设备)更改DB中的值时,然后回到PC并在同一位置读取相同的值,返回与什么不同我可以在DB上看到。

这是我注意到的检索代码

var DBTask = await m_DBReference.Child("users").Child(m_User.UserId).Child("EnergyData").Child("CurrentEnergy").GetValueAsync();

    if (DBTask.Value == null)
    {
        //no data contained
        energyData.iEnergy = 20;//Default starting value
    }
    else
    {
        energyData.iEnergy = int.Parse(DBTask.Value.ToString());
        print("Direct DB energy = " + energyData.iEnergy);
    }

,只有在一个设备中更改DB中的值(我能够看到更改发生在Firebase Console中),然后尝试从同一位置获得相同的值DB,我得到了另一个,很奇怪的是,它并不总是发生。

I need to retrieve a value stored in my firebase Realtime DB. It works well so far but i have found a bug that when you are on one device (mobile) change the value in the DB and then you go back to pc and read the same value in the same place, the return is different than what i can see on the DB.

Here is the retrieving code

var DBTask = await m_DBReference.Child("users").Child(m_User.UserId).Child("EnergyData").Child("CurrentEnergy").GetValueAsync();

    if (DBTask.Value == null)
    {
        //no data contained
        energyData.iEnergy = 20;//Default starting value
    }
    else
    {
        energyData.iEnergy = int.Parse(DBTask.Value.ToString());
        print("Direct DB energy = " + energyData.iEnergy);
    }

I am noticing this only happens when changing the value in the DB in one device (i am able to see the change happened in the firebase console), then whn trying to get the same value from the same place in the DB, i get a different one, weird thing is that it doesnt happen always.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文