Reputation: 524
How can I get the kaarsen
array out of my Firebase database of every single user?
Upvotes: 0
Views: 52
Reputation: 125
let userID = FIRAuth.auth()?.currentUser?.uid
ref.child("users").child(userID!).child("kaarsen").observeSingleEvent(of: .value, with: { (snapshot) in
// Get user value
let value = snapshot.value as! Array
arrayOfKarsens.append(value)
// ...
}) { (error) in
print(error.localizedDescription)
}
Upvotes: 0
Reputation: 598847
You seem to be nesting different types of data, which is a big anti-pattern in the Firebase Database. When you read data from Firebase, you always read entire nodes. So in your scenario you either read the entire user, or you don't read them. You cannot retrieve just the kaarsen
node for each user. This is one of the many reasons why Firebase recommends against nesting different types of data.
In your case it seems best to split the kaarsen int a top-level node:
users
<uid>
email: ...
geboortedatum: ...
naam: ...
kaarsen
<uid>
...
With this structure you can get the kaarsen
for all users by accessing /kaarsen
.
Upvotes: 1