-2

I次のようなデータ構造を有する:値は、関数

enter image description here

どのように私は完全に「日」は、クラウド機能を使用して削除しますか?

私の現在のコード:

const functions = require('firebase-functions'); 
const admin = require('firebase-admin'); 
admin.initializeApp(functions.config().firebase); 

    exports.deleteOldItems = functions.database.ref('/path/to/items/{pushId}') 
    .onWrite(event => { 
     var ref = event.data.ref.parent; // reference to the items 
     var now = Date.now(); 
     var cutoff = now - 2 * 60 * 60 * 1000; 
     var oldItemsQuery = ref.orderByChild('timestamp').endAt(cutoff); 
     return oldItemsQuery.once('value', function(snapshot) { 
     // create a map with all children that need to be removed 
     var updates = {}; 
     snapshot.forEach(function(child) { 
      updates[child.key] = null 
     }); 
     // execute all updates in one go and return the result to end the function 
     return ref.update(updates); 
     }); 

functions.database.ref('/days').remove(); // <- /days doesn't get removed 

    }); 

答えて

1

あなたが削除を呼び出す前に、関数から戻ってきています。試してください:

return oldItemsQuery.once('value', function(snapshot) { 
    // create a map with all children that need to be removed 
    var updates = {}; 
    snapshot.forEach(function(child) { 
     updates[child.key] = null 
    }); 
    // execute all updates in one go and return the result to end the function 
    return ref.update(updates); 
    }).then(function() {; 
    return functions.database.ref('/days').remove(); 
    }); 
+0

コードが機能しません。これをチェックしてください。 –

+0

何が問題なのですか?エラーメッセージが表示されますか? –

+0

@FrankvanPuffelenエラーメッセージは表示されません。 「日」は削除されません。 –