Skip to content

Instantly share code, notes, and snippets.

@davidgilbertson
Created May 26, 2016 08:14
Show Gist options
  • Save davidgilbertson/3508834be0dd4818c1c5ccd6d47536fa to your computer and use it in GitHub Desktop.
Save davidgilbertson/3508834be0dd4818c1c5ccd6d47536fa to your computer and use it in GitHub Desktop.
db = firebase.database().ref('test');
const userId = firebase.auth().currentUser.uid;
function removeStudent(studentKey) {
db.child('data/students').child(studentKey).once('value', (studentSnapshot) => {
const student = studentSnapshot.val();
const courseKeys = Object.keys(student.courseKeys);
const removeData = {
[`data/students/${studentKey}`]: null,
[`data/schools/${student.schoolKey}/studentKeys/${studentKey}`]: null,
[`users/${userId}/studentKeys/${studentKey}`]: null,
};
courseKeys.forEach(courseKey => {
removeData[`data/courses/${courseKey}/studentKeys/${studentKey}`] = null;
});
db.update(removeData);
});
}
removeStudent('<some student key>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment