This script is a copy of this thread in the UI community forums code, but reformatted.
It's purpose is to clean up the UniFi Controllers MongoDB regularily and should probably best be used with a cron job.
The official docs can be found here.
Usage:
Switch var dryrun = false;
before running the script.
# `27117` is the default MongoDB port
# If not, @see `/var/lib/unifi/system.properties` for `unifi.db.port=27117` that should hold the port if uncommented.
mongo --port 27117 < mongo_prune_js.js
If MongoDB crashed and is not running:
sudo systemctl start mongod
The code is a 1:1 mirror of what is officially availabel via UI help and untested yet (02.2022).
The license and usage is unknown. Please contact me directly if you have concerns or need to have this taken down.