1

I intend to structure my firebase database as follow.... there is a one user to many book relationships

test-a1dd - users - c7ffe6dassfasdfadsf - name - age - school - books - fasdfhgajhdjhfkjadhg - title: 'Yeah' 

However, when i push data into firebase in the method as shown below, i get an extra id which is expected since I'm pushing in as an object

export const addUserInfo = ({ name, description }) => { return dispatch => { try { const { currentUser } = firebase.auth(); firebase.database().ref(`/users/${currentUser.uid}`) .push({ name, description }) .then(() => { console.log('User Details Updated') }) } catch (error) { console.log('Update User Details Error', error) } } } 

Any experienced firebase folks can share with him how to push data onto firebase to achieve the firebase structure I desire?

Alternatively, if the firebase data structure I desire is not possible, how can I separate the object 'name, school and age' from the object 'books' so I can display in my list accordingly?

Thanks in advance for your help

1 Answer 1

1

When you push it generates a key for you. If you use set or update it writes the object as you supplied.

firebase.database().ref(`/users/${currentUser.uid}`) .set({ name, description }) .then(() => { return firebase.database().ref(`/users/${currentUser.uid}/books`) .push({ title: 'Yeah' }); }); 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks sketchthat!! :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.