Reputation: 2487
Working with Firebase for iOS real-time database to create a record each time a user performs a certain action on my App. However, all I see in the documentation is setValue. Therefore, it overwrites what I had before, and I want to keep the history so it can be queried and aggregated on the phone.
This works as it adds it to the database.
let roofRef = Database.database().reference()
roofRef.child("user123").setValue(["activity": "running", "score": "52"])
However, I'm looking to add another activity or even the same with an new score. So each time the activity is done, a new entry is made into the database under the same child = "user123".
Upvotes: 0
Views: 141
Reputation: 751
You could make an extra database node which would be a unique ID for each report. So the database structure would be: User -> Unique report ID -> Report.
Code:
let roofRef = Database.database().reference()
roofRef.child("user123").childByAutoId().setValue(["activity": "running", "score": "52"])
Upvotes: 1