This template shows how to keep the number of child nodes in a Firebase database below a given number. This can be used to limit the number of lines of a chat history or logs.
## Cloud Function Code
## Functions Code
See file [index.js](index.js) for the code.
See file [index.js](function/index.js) for the code.
The dependencies are listed in [package.json](package.json).
The dependencies are listed in [package.json](function/package.json).
## Sample Database Structure
@ -23,21 +23,4 @@ As an example we'll be using a simple chat database structure:
text: "Hey Mat! What's Up?"
```
## Trigger rules
Below is the trigger rule for the `truncate` function making sure it's triggered when a new chat message is added.
```
"functions": {
".source": "functions",
"truncate": {
"triggers": {
"database": {
"path": "/chat/$messageid"
}
}
}
}
```
Every time a new chat message is added the Function runs. It counts the number of chat messages and removes the old ones if there are too many.