I have the following Firebase code:
https://gist.github.com/balazsorban44/52c2858aa10f6269c7a9b3c0cfa247d5
I would like to get a js object of all the reservations', but only the public parts, since the details are only viewable for the admins.
I tried the following:
let reservations = {}
firebase.database().ref('reservations').once('value', snapshot => {
snapshot.forEach(reservation => {
reservations[reservation] = reservation.val().public
})
})
But it does not work. Where am I failing?
Should I create a reservationsPublic and a reservationsPrivate object, so I can more easily fetch the info I need? In this case, when a user fills out a reservation form, should I split the input into two and put half of it into the reservationsPublic and the rest to the reservationsPrivate?
EDIT:
I think I found the solution for my problem here:
https://stackoverflow.com/a/38649032/5364135
So I have to write to the database twice, to improve the read performance, if I understood it correctly.