Saturday 15 April 2017

Bulk-delete items from a firebase database in node.js

I'm trying to delete all nodes with a date greater than '2017-04-05' with a bulk operation with a firebase function. Can you spot what I'm doing wrong here?

The 2 nodes that should get deleted are the ones in red: enter image description here

Here's the code that is failing - can you see what's wrong? Also, I'm concerned about the performance of this (I'll only run it once in a while though). If there are millions of games in the list, should that concern me if I only run this once a day?

exports.remove = functions.https.onRequest((req, res) => {

    const deleteBeforeDate = req.query.deleteBeforeDate;

    var ref = admin.database().ref('games');

    var keysToDelete = {};
    for (var game in this.games) {

        var date = items[i]['.date'];
        if(date.value > '2017-04-05'){
            keysToDelete[game.key] = null;
        }
    }
    this.ref.update(keysToDelete);
});

Thank you very much,

Mike



via Mike Gagnon

No comments:

Post a Comment