Reputation: 728
I have a big database in Firebase. In my opinion it's wrong structured. Trying to get a snapshot of reference, It takes too much time processing the results. However, I don't need to retrieve all data. I don't need the deepers items but I don't know how can I get the superficials.
So the structure is something like this:
clients {
1234 {
name: 'Paul',
last_name: 'Mcartney',
city: 'Liverpool',
account_movements: {
item1: {
...
}
}
}
1234 { ... }
1236 { ... }
}
Let's supose that what I need is all clientes data except his account_movements
.
Upvotes: 1
Views: 361
Reputation: 138899
Because you are talking about a big database i suggest you restructure your database a little bit. As Frank says, when you are trying to read a node, you get the entire node. This means that every time you add a listener to specific reference, you are downloading the entire information of that object. Note, that there is no way in which you can download only a subset of the properties of each node and that's why you need to denormalize
your database. Because an important rule in Firebase is to have the database as flatten as possible, i suggest you get the account_movements
out from each user and add it separately as a top-level node. To understand better, i suggest you read this post, Structuring your Firebase Data correctly for a Complex App and see this tutorial, Denormalization is normal with the Firebase Database.
Hope it helps.
Upvotes: 1
Reputation: 617
You can either create new nodes "account_movements" with their own ids and add them to user or you can create another node for users that doesn't have details about users. Second solution requires more space, but it is easier to make read operations as you only need to create 1 call (user with details or without) instead of reading id of account_movements to create second call. In this example you can name id of account_movements with user's id. But that's not always possible
Upvotes: 0