Created
May 26, 2016 08:14
-
-
Save davidgilbertson/3508834be0dd4818c1c5ccd6d47536fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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