This post says that FireBase will have an issue coming when an individual node begins to have 1-10+ million children. How should one handle Users in an app if we have more than 10 million? In all the examples I though Users were simply children of a single node "Users".
问题:
回答1:
Firebase is not ideal for processing long lists of items. The problem with these long lists is not so much storing the data as it is accessing the data.
Whenever you access the list (e.g. ref.child('users').on(...
) Firebase has to consider all items in that list on the server; even when you are only downloading a few users (.limitToLast(10)
), it has to consider each user.
But as long as you never try to access the list, you can store as many users under there as you want. But that means that you always access them directly, e.g. ref.child('users').child(auth.uid).on(...
.
This limits the use-cases you can implement, so typically developers create sublists of users by how they need to use them. For example if each user is keeping a list of friends, you could keep those like ref.child('users_friends').child(auth.id).on(...
and look each of them up with ref.child('users').child(auth.uid)
again. That way, you're only reading a small list of users and then loading each of those users directly.