Minimal Docker-Compose Example
Local Management
In order to manage mongo instances you can use Mongo Shell for interacting with databases and the Mongo DB Tools package for management operations like dumping and restoring data.
Initialization with Docker
The above config creates a user in the admin
DB which we can then use to set up more databases and users.
Creating a Database
To create a new database and user in MongoDB, you can use the following commands:
Create a new database and grant a new user permissions on it:
- Connect to the admin database using mongosh:
- Run
use mynewdatabase
to create a new db calledmynewdatabase
- Now the local
db
variable will refer to the db you just created and we can create the user: