How to Auto Provision MongoDb using JavaScript
How to Auto Provision MongoDb
After the MongoDb installation, you want to configure it, add users and permissions, create databases and populate them with collections. And we want the script the entire MongoDb provisioning process.
We start right after MongoDb has been installed. The 4 most common MongoDb script install strategies are
- Linux Bash (Shell) Scripts
- Ansible‘s MongoDb Module
- Cloud Provisioning (eg AWS MongoDb)
- Chef, Puppet and/or CFEngine
MongoDb is part of a new breed of JavaScript fronted middleware services. So the JavaScript provisioning required by MongoDb isn’t common, hence this guide.
10 Steps | Configuring and Populating MongoDb
Let’s use a simple provisioning plan to configure and populate MongoDb. We’ll use Ruby’s magic to create the strong passwords. In step 2, we call on Mongo to execute our JavaScript code.
- generate 2 strong passwords for the 2 users
- ask the mongo shell to execute our JavaScript
- create the mongodb admin user (using password)
- authenticate as our new administrator user
- create a database for the application
- create a readWrite user for the app db
- exit the mongodb shell into the op sys shell
We could load the application data from within the Mongo shell, but it is rather awkward. The mongoimport provides a simpler way to achieve this step.
So the final 3 steps are to
- use mongoimport to pour in the app data
- smoke test the mongodb persistence service
- inject db properties into app environment