Here is the following data structure :
{
"list" : {
"-K4YlfoWHZqPyWONv68Y" : {
".priority" : -1.449077948445E12,
"date" : 1449077948445,
"id" : "0",
"name" : "Name_0"
},
"-K4YlfoWHZqPyWONv68Z" : {
".priority" : -1.449077948445E12,
"date" : 1449077948445,
"id" : "1",
"name" : "Name_1"
},
"-K4YlfoWHZqPyWONv68_" : {
".priority" : -1.449077948445E12,
"date" : 1449077948445,
"id" : "0",
"name" : "Name_2"
},
"-K4YlfoWHZqPyWONv68a" : {
".priority" : -1.449077948445E12,
"date" : 1449077948445,
"id" : "1",
"name" : "Name_3"
},
...
}
I need to only get item where id is "0";
The following is working :
final Firebase ref = new Firebase("https://millezim-test.firebaseio.com/").child("list");
ref.orderByChild("id").equalTo("1").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot d : dataSnapshot.getChildren()) {
Model m = d.getValue(Model.class);
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
But not this one, why ?
ref.equalTo("1","id").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot d : dataSnapshot.getChildren()) {
Model m = d.getValue(Model.class);
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
Did I misunderstand that equalTo("value","key") is to use without reordering By something ?
In Firebase Database everything is a node, that follows the pattern key: value. Firebase Database provides us with a simple way to generate unique keys. Unique keys create new items while uploading data to a previously stored key will update.
Firebase uses a very popular style of NoSQL database: Key-value stores. The concept is not so complicated once you know the basic JSON syntax.
Calling the getKey() method on this reference will return the auto-generated key which may then be used to store a corresponding value. The following code, for example, uses the push() method to add a new child at the path stored within the database reference instance: DatabaseReference newChildRef = dbRef.push();
The limitToFirst() method is used to set a maximum number of children to be synced for a given callback. If we set a limit of 100, we will initially only receive up to 100 child_added events. If we have fewer than 100 messages stored in our Database, a child_added event will fire for each message.
The Firebase documentation for equalTo says this about the (optional) key
parameter:
The child key to start at, among the children with the previously specified priority. This argument is only allowed if ordering by priority.
Since you're not ordering by priority, you'll need to specify the child with an explicit call to orderByChild()
.
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