Reputation: 51
1.DatabaseReference db=FirebaseDatabase.getInstance().getReference("users");
1.Query query = db.orderByKey().equalTo(uid);
2.FirebaseDatabase.getInstance().getReference("users").orderByChild("token").equalTo(toKen)
Does any one of the above two codes written in Java Android Studio send the entire "users" node of Realtime Database to the client Android App or Only the the Fetched Records will be send to the client Android App. It Seems like that it sends the complete "users" node to the client Android App, because my realtime database bill is quite high and customers are low.
Upvotes: 0
Views: 147
Reputation: 598718
If the download size is higher than you'd expect based on the number of query results, check if you've defined an index on the token
property. If no such index exists, Firebase will download all data under users
to the client, and perform the sort/filter there. If an index is declared, the ordering/filtering is done on the server.
Upvotes: 1
Reputation: 50830
It seems you are looking for orderByChild()
. To get the child node where the value of uid
is equal to passed UID, try this:
DatabaseReference db=FirebaseDatabase.getInstance().getReference("users");
Query query = db.orderByChild("uid").equalTo(uid);
The documentation says,
Method | Usage |
---|---|
orderByChild | Order results by the value of a specified child key or nested child path. |
orderByKey | Order results by child keys. |
The second query looks fine and should fetch the node where the value of token
is equal to the supplied token.
Upvotes: 1