I am using Firebase console for preparing data for a demo app. One of the data item is attendees. Attendees is an array. I want to add a few attendees as an array in Firebase. I understand Firebase does not have arrays, but object with keys (in chronological order). How do I do that for preparing sample data? My current Firebase data looks like the below.
相关问题
- How to get the maximum of more than 2 numbers in V
- Faster loop: foreach vs some (performance of jsper
- adding sha1 in firebase app fails with error
- Convert Array to custom object list c#
- pick a random item from a javascript array
相关文章
- Numpy matrix of coordinates
- How can make folder with Firebase Cloud Functions
- PHP: Can an array have an array as a key in a key-
- Accessing an array element when returning from a f
- How can I convert a PHP function's parameter l
- How to make a custom list deserializer in Gson?
- Recursively replace keys in an array
- React Native - Dynamic Image Source
firebase array ?yeah, i have same problem with you few weeks ago, but i found it in here. Finally i can use it with my ChartJS.
The Firebase Database doesn't store arrays. It stores dictionaries/associate arrays. So the closest you can get is:
You can build this structure in the Firebase Console. And then when you read it with one of the Firebase SDKs, it will be translated into an array.
So this may be the result that you're look for. But I recommend reading this blog post on why Firebase prefers it if you don't store arrays: https://firebase.googleblog.com/2014/04/best-practices-arrays-in-firebase.html.
Don't use an array, when you actually need a set
Most developers are not actually trying to store an array and I think your case might be one of those. For example: can "Bill Gates" be an attendee twice?
If not, you're going to have to check whether he's already in the array before you add him.
This is a clear sign that your data structure is sub-optimal for the use-case. Having to check all existing children before adding a new one is going to limit scalability.
In this case, what you really want is a set: a data structure where each child can be present only once. In Firebase you model sets like this:
And now whenever you try to add Bill Gates a second time, it's a no-op:
So instead of having to code for the uniqueness requirement, the data structure implicitly solves it.
After writing my other answer I realized that you might simply be looking how to add push IDs in the console.
That's not a feature at the moment. Most of is either use different types of keys when entering test data or have a little JavaScript snippet in another tab to generate the keys and copy/paste them over.
Please do request the feature here, since you're definitely not the first one to ask.