简体   繁体   English

如何在 Firebase (Kotlin) 中获取特定数据

[英]How can I get a specific data in Firebase (Kotlin)

I need to retrieve the "administrator" value from Firebase我需要从 Firebase 中检索“管理员”值Firebase 数据库

This is the code I use:这是我使用的代码:

FirebaseDatabase.getInstance().getReference("/restaurants/$restaurantUID/administrator")
            .get().addOnSuccessListener {

            Log.d("key", it.toString())
        }

The result in the log is this though: 2022-09-05 17:07:32.271 2885-2885/com.example.menuapp D/key: DataSnapshot { key = administrator, value = null }日志中的结果是这样的: 2022-09-05 17:07:32.271 2885-2885/com.example.menuapp D/key: DataSnapshot { key = administrator, value = null }

How can I get the actual value for "administrator" and not a null?如何获得“管理员”的实际值而不是 null?

According to your last comment, I see that value of restaurantUID is:根据您的最后评论,我看到restaurantUID的值是:

eefef966-f227-45e8-b875-f568b87ee1fc

Which is totally different than the one in the database.这与数据库中的完全不同。 The one in the database strats with "c20f02b0-...", hence that null for the value of administrator filed.数据库中的一个带有“c20f02b0-...”,因此 null 为administrator归档的值。 If you want to get the correct value, then always make sure you're reading the data on the correct path:如果您想获得正确的值,请始终确保您在正确的路径上读取数据:

val restaurantUID = "eefef966-f227-45e8-b875-f568b87ee1fc"
val db = FirebaseDatabase.getInstance().reference
val adminRef = db.child("restaurants/$restaurantUID/administrator")
adminRef.get().addOnSuccessListener {
    Log.d("key", it.toString())
}

Try this -尝试这个 -

FirebaseDatabase.getInstance().getReference("/restaurants/$restaurantUID").orderByChild("administrator").equalTo(“Alr6tf3nzTNTXbx53ysbcAxcM643”).addChildEventListener(new ChildEventListener() {
  @Override
  public void onChildAdded(DataSnapshot dataSnapshot, String prevChildKey) {
    System.out.println(dataSnapshot.getKey());
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Kotlin 从 Firebase 获取特定数据 - How to get specific data from Firebase with Kotlin 如何从 firebase 数据快照中获取特定的 snapkey - How do I get a specific snapkey from firebase data snapshot 如何将我的应用程序从 firebase 获取的数据设置到我的 bottomSheetView? (科特林) - How can I set the fetched data of my app from firebase to my bottomSheetView? (Kotlin) 如何从 Firebase Firestore 获取 ReactJs 的数据? - How Can I get data with ReactJs from Firebase Firestore? 我如何不重复地从firebase数据库中获取数据 - how I can get data from the firebase database without repeat 如何使用 window 服务自动获取 firebase 数据 - How can i get firebase data automatically using window service 如何获取到Firebase最后上传的数据? - How can I get the last uploaded data to Firebase? 我无法从特定用户获取 firebase 的数据(使用 uid 检查方法) - I can not get data from firebase from a specific user (using the uid check method) 我在数组中遇到问题我从 firebase (firestore) 获取数据,我想显示数据数组我该怎么做? - I face a problem in the array I get the data from firebase (firestore) and I want to show array of data how can i do? Firebase Realtime Database 数据检索的进度可以获取吗? - Can I get the progress of a Firebase Realtime Database data retrieval?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM