A simple stitch app to run as a cron service on MongoDB Stitch, using MongoDB TTL.
This repository contains a stitch app configured as a database trigger for a DELETE event.
The DELETE event occurs when a document within a collection containing a TTL index is deleted. The app then inserts a new document into the collection with the current date, thus causing a rough timed loop.
-
Install node. This repository's node version can be found in .nvmrc.
-
Install yarn.
-
Sign up for MongoDB Stitch
-
Install the Stitch CLI.
-
Make a cluster, and add the cluster name in the atlas config.json.
-
Generate an atlas API key.
-
Login to stitch:
stitch-cli login --username=<MongoDB Cloud username> --api-key=<MongoDB Atlas API Key>
-
Modify the code in source.js to your needs. Ensure that you re-insert the deleted key back into the database.
-
Deploy the stitch app and link it to your cluster:
stitch-cli import
- Install dependencies:
yarn install
- Setup the database TTL index and insert a document.
MONGODB_HOST=<your mongodb connection string> node setup.js
You can view the logs for the stitch app in the left side of your stitch app dashboard.
Resource | Description |
---|---|
Stitch Docs | MongoDB Stitch Documentation |
MongoDB Docs | MongoDB Documentation |
MongoDB Community Slack | MongoDB Community Slack |
DatabaseTriggers | Setting up Stitch apps as database triggers |
Database TTL | Expire data from a collection by setting a TTL |