Pull request Compare This branch is 6 commits ahead, 146 commits behind Node-8.
nicolasgarnier Upgrade all firebase-admin imports to 5.11.0
Change-Id: Ib3f6a5f57d3fdd0dbc2ee3d27efbd3cf00966257
Latest commit 849ab0b Mar 26, 2018
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
functions
README.md

README.md

Removing old items from a list

This sample shows how to remove child nodes older than 2 hours from a Firebase Database list. This can be useful for removing outdated items from a collection.

Functions Code

See file functions/index.js for the code.

Note that this code only runs when triggered by a write to the list. This means that if nothing gets written for a while, the list may still contain outdated items. If that does not match with your use-case, you should modify the code to trigger based on a time-interval as shown in this sample.

The dependencies are listed in functions/package.json.

Sample Database Structure

The example uses the database structure shown below:

/functions-project-12345
    /path
        /to
            /items
                item1: {
                    timestamp: 1497911193083
                },
                item2: {
                    timestamp: 1597911193083                    
                }
                ...

The default cutoff interval is 2 hours, meaning that items older than 2 hours are deleted. You can modify the code to match your database structure and cutoff requirements.