0

complete noob here.

Trying to retrieve the firebase unique id from the first data push to use in the second so that I can reference the data between the two data sets. I used stackoverflow answers to retrieve the key, but my code didnt work.

(If you have a better way of referencing the two items other than utilizing firebase unique id, Im all for it!) thanks!!

export const GROUP_CREATE = 'group_create'; export const groupCreate = ({ name, course, members }) => { const { currentUser } = firebase.auth(); return (dispatch) => { var pushedRef = firebase.database().ref(`/groups`).push({ name }) var dataId = pushedRef.key .then( firebase.database().ref('/groups') .push({ name, dataId, course, members })) .then(() => { dispatch({ type: GROUP_CREATE }); Actions.groupMain({ type: 'reset' }); }); }; }; 

enter image description here

1 Answer 1

1

I figured it out!

export const GROUP_CREATE = 'group_create'; export const groupCreate = ({ name, course, members }) => { const { currentUser } = firebase.auth(); var myRef = firebase.database().ref('/groups').push(); var groupId = myRef.key; return (dispatch) => { myRef.push({ name, course, members }) .then( firebase.database().ref(`/users/${currentUser.uid}/groups`) .push({ name, groupId })) .then(() => { dispatch({ type: GROUP_CREATE }); Actions.groupMain({ type: 'reset' }); }); }; }; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.