Member-only story

MongoDB

Get started with MongoDB

using Docker and Docker Compose.

Donald Le

--

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~~

--

--

No responses yet