{
"random_key 1" : {
"id": 0,
"text": "This is text"
},
"random_key 2" : {
"id": 1,
"text": "This is text"
}
}
If I'm storing my data like this, and I want to get the node where id
is equal to 0
. How can I do that?
The above is the child of issue
, which is a child of root
.
Querying DataWith Firebase database queries, you can selectively retrieve data based on various factors. To construct a query in your database, you start by specifying how you want your data to be ordered using one of the ordering functions: orderByChild() , orderByKey() , or orderByValue() .
Firebase data is retrieved by either a one time call to GetValueAsync() or attaching to an event on a FirebaseDatabase reference. The event listener is called once for the initial state of the data and again anytime the data changes.
Firebase and MySQL Differences Firebase uses NoSQL; MySQL uses SQL.
Automatic Scaling As and when there is a change in data, Firebase helps in the calculation of the minimum set of updates needed to keep all your clients synchronized. Additionally, the API functions of firebase are designed in order to scale linearly with the size of data being synchronized.
In your case you would have to setup a Query like this:
DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
Query query = reference.child("issue").orderByChild("id").equalTo(0);
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
// dataSnapshot is the "issue" node with all children with id 0
for (DataSnapshot issue : dataSnapshot.getChildren()) {
// do something with the individual "issues"
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With