0

I'm trying to view my current realtime database's data on the firebase console, but it appears as null. I'm definitely writing to the database correctly as the below listener returns me the correct information when i use the setValue function. Does anyone know if it just takes a few hours to reflect on the firebase console or there's something im missing here?

    firebaseAuth.currentUser?.uid?.let {
        db.getReference("users").child(it).addValueEventListener(object : ValueEventListener {
            override fun onDataChange(snapshot: DataSnapshot) {
                val user = snapshot.getValue(User::class.java)
                Log.d("username", user?.username.toString())
                Log.d("favSport", user?.favouriteSport.toString())
            }

            override fun onCancelled(error: DatabaseError) {
                TODO("Not yet implemented")
            }

        })
    }

enter image description here

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
alfietap
  • 1,585
  • 1
  • 15
  • 38

2 Answers2

4

Found the issue if this helps anyone in the future: I'd downloaded and linked my firebase account with google-services.json BEFORE creating and linking the real-time database, which meant my google-services didn't contain the firebase_url for my database, so I just re-downloaded the google-services.json and restarted my project, all working now

alfietap
  • 1,585
  • 1
  • 15
  • 38
1

The Firebase console always shows the up-to-date information that is stored in the database servers. If it shows no data, it is more likely that the data hasn't made it to the servers yet. For example: does your device have an internet connection?

You might also want to attach a completion listener to the write operation. A completion listener only fires once the data is written on the server, so if it doesn't fire that would confirm that the data doesn't make it to the server.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • I've added the completion listeners and as described they don't fire. This seems odd as the onDataChange method fires inside the addValueEventListener with the correct info which according to the docs only triggers when the data in your database changes? Do you recommend checking anything else? My device has internet etc. – alfietap Nov 14 '21 at 18:10
  • 1
    The `onDataChange` immediately fires for local events, so that's most likely what you're seeing. I'd check the logcat output of your app when the write happens to see if there are any errors. If nothing relevant shows up, [enabe debug logging](https://firebase.google.com/docs/reference/android/com/google/firebase/database/FirebaseDatabase.html#setLogLevel(com.google.firebase.database.Logger.Level)) and try again. – Frank van Puffelen Nov 14 '21 at 18:39
  • I found the issue, i linked my firebase before creating the realtime database so needed to update my google services.json. Thank you for your help – alfietap Nov 14 '21 at 18:50
  • Good to hear you found the issue. "Thank you for your help" -> Don't forget to hit the upvote button if my answer was helpful in solving the problem. :) – Frank van Puffelen Nov 14 '21 at 18:54