I have a list of users, assume 10k.
Now if I run a query like below:
query = FirebaseDatabase.getInstance().getReference().child("users")
.orderByChild(SELECTED_QUERY)
.limitToFirst(150);
Will it consume bandwidth of 150 users' data
or 10k users' data
?
This question may be silly, but I haven't found expected answer.
CodePudding user response:
Whether the SDK retrieves all users
or just the first 150 depends on whether you've defined an index on SELECTED_QUERY
. Without an index the SDK will retrieve all of users
and filter locally on the client; with the index the filtering will happen on the server.
Given your comment, you'll need to add an index to your rules like this:
{
"rules": {
...
"users": {
...
".indexOn": "name"
}
}
}
CodePudding user response:
Will it consume bandwidth of 150 users' data or 10k users' data?
Just for the amount of data received i.e. 150 users in this case. That is why you should paginate your queries. Querying large amount of redundant data at once will take more time to load and also increase the costs.