Documentation
¶
Overview ¶
go run example_mongo.go
Run a single MongoDB via Docker:
docker run -d --name mongodb -e MONGO_INITDB_ROOT_USERNAME=test -e MONGO_INITDB_ROOT_PASSWORD=test -e MONGO_INITDB_DATABASE=test -p 27017:27017 mongo:4.2
Setup env:
export MONGO_DB="test" export MONGO_URL="mongodb://test:test@localhost:27017/?authSource=admin"
go run example_mongo_replset.go
Run a replica-set MongoDB via Docker:
docker run -d --name mongodb-replset -e MONGODB_REPLICA_SET_MODE=primary -e MONGODB_REPLICA_SET_KEY=myreplset -e MONGODB_ADVERTISED_HOSTNAME=localhost -e MONGODB_PRIMARY_PORT_NUMBER=27017 -e MONGODB_ROOT_PASSWORD=test -e MONGODB_DATABASE=test -p 27017:27017 bitnami/mongodb:4.2
Setup env:
export MONGO_DB="test" export MONGO_URL="mongodb://root:test@localhost:27017/?authSource=admin&replicaSet=replicaset"
Click to show internal directories.
Click to hide internal directories.