0

I have a dynamic list/array of users that I want to add to my firebase db. I looked at Setting arrays in Firebase using Firebase console which suggested to store arrays like the following data structure:

uid: {
attendees: {
  "Bill Gates": true,
  "Larry Page": true,
  "James Tamplin": true
}
}

However, creating a dictionary and adding them one by one to the user field is inefficient:

let dict: Dictionary<String, Any> =  [
    "location": "",
    "attendees": {
       "Bill Gates": true,
       "Larry Page": true,
       "James Tamplin": true,
       ....
    }
]

If I have 100 attendees, it's inefficient to add them one by one to my dictionary and set each of its value to true. How can I add my data more compactly? When I get back the user dictionary, how can I retrieve each key in attendees?

Joan
  • 905
  • 2
  • 9
  • 15

1 Answers1

1

I am not sure what will be the more efficient way of setting up a list of attendees with true or false indicating if they are joining the program or not. In any way, you will have to set the data of their availability one by one after you're getting it from somewhere else.

I think you can create a dictionary with your attendees and their availability and push the dictionary altogether with a single firebase operation. Once you are done with preparing the dictionary that you want to push you can consider saving the values in your firebase database as follows.

databaseRef.child("events").child(someKey).updateChildValues(attendeesDictionary) 
Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98