This is a simple script that will keep the database users in sync with a defined JSON document.
My ultimate use case is in a K8S environment so the files will be templated and I will add and remove users from my databases that way.
This is the test rig and shows how to manage the creation, updating and deletion of MongoDB users.
- docker-compose.yml - Starts containers
- env_file - Contains the environment variables
- mongo-user.py - The code
- requirements.txt - The python requirements
- users.json - A simple JSON document the python script reads to handle the users
docker-compose up -d mongo
sleep 5
docker-compose up script
Add a new item to the mongo_users
key in users.json
or change the password or roles.
Remove the user object from mongo_users
in users.json