I writed a firebase cloud functions but its working only 70% when i do multiple delete ! and it's very slow ? what im doing wrong ??
here is my function :
exports.deleteQuestion = functions.database.ref('questions_for_mars/{pushId}').onDelete(event => {
const original = event.val()
idQuestion = event.key
authorQuestion = original.author
//console.log('event', original.answers)
admin.database().ref('counter/questions_active').once('value').then((snapshot) => {
var questions_active = snapshot.val()
var updateQuestions = {};
event.child('answers').forEach(child => {
var mars = child.key
updateQuestions['/my_answers/' + mars + '/' + idQuestion] = null
updateQuestions['/mars/' + mars + '/counter/answers_active'] = questions_active - 1
console.log('question active', original)
});
updateQuestions['/counter/questions_active'] = questions_active - 1
updateQuestions['/my_questions/' + authorQuestion + '/' + idQuestion] = null
updateQuestions['/my_questions_send/' + authorQuestion + '/' + idQuestion] = null
updateQuestions['/questions/' + idQuestion] = null
//updateQuestions['/my_answers/' + authorQuestion + '/' + idQuestion] = null
console.log('UPDAYE', updateQuestions)
return admin.database().ref().update(updateQuestions)
})
});