Delete firebase data older than 2 hours

后端 未结 5 767
太阳男子
太阳男子 2020-11-22 03:17

I would like to delete data that is older than two hours. Currently, on the client-side, I loop through all the data and run a delete on the outdated data. When I do this, t

5条回答
  •  旧巷少年郎
    2020-11-22 03:59

    In the latest version of Firebase API, ref() is changed to ref

    var ref = new Firebase('https://yours.firebaseio.com/path/to/items/');
    var now = Date.now();
    var cutoff = now - 2 * 60 * 60 * 1000;
    var old = ref.orderByChild('timestamp').endAt(cutoff).limitToLast(1);
    var listener = old.on('child_added', function(snapshot) {
        snapshot.ref.remove();
    });
    

提交回复
热议问题