MongoDB

Get started with MongoDB

using Docker and Docker Compose.

Photo by Usukhbayar Gankhuyag on Unsplash

Pull the latest mongodb docker image from dockerhub

docker pull mongo:latest

init-mongo.js

db.createUser(
{
user : "username",
pwd : "password",
roles : [
{
role : "readWrite",
db : "testing"
}
]
}
)

docker-compose.yml

version: '3'
services:
database:
image: 'mongo'
container_name: "mongodb-container"
environment:
- MONGO_INITDB_DATABASE=testing
- MONGO_INITDB_ROOT_USERNAME={username}
- MONGO_INITDB_ROOT_PASSWORD={password}
volumes:
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
- ./mongo-volume:/data/db
ports:
- '27017-27019:27017-27019'

Up from the current directory

docker-compose up

Working with MongoDB via DataGrip

Data grip

Create a new collection

db.Medium.insertOne({ testing: 1})

Get collection info

db.getCollectionInfos()

Hope it helps.

~~ Happy coding~~

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store