In this example, we use this database:
"your-project-name" : {
"users" : {
"randomUserId1" : {
"display-name" : "John Doe",
"gender" : "male"
}
"randomUserId2" : {
"display-name" : "Jane Dae",
"gender" : "female"
}
},
"books" {
"bookId1" : {
"title" : "Adventure of Someone"
},
"bookId1" : {
"title" : "Harry Potter"
},
"bookId1" : {
"title" : "Game of Throne"
}
}
}
If you use above database then:
FirebaseDatabase.getInstance().getReference()
will point at your project's parent, "your-project-name"
data. So the dataSnapshot
you acquired will contain all of data inside it, including all of "users"
data and "books"
data.
FirebaseDatabase.getInstance().getReference("users")
and FirebaseDatabase.getInstance().getReference().child("users")
will have the same result, pointing at "your-project-name/users"
FirebaseDatabase.getInstance().getReference("users/randomUserId1")
and FirebaseDatabase.getInstance().getReference().child("users/randomUserId1")
and FirebaseDatabase.getInstance().getReference().child("users").child("randomUserId1")
will have the same result, pointing at "your-project-name/users/randomUserId1"
Note: this example is needed to fully understand which data is inside dataSnapshot object