Skip to content

thangtranse/mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Intro Mongo with NodeJS

REQ

Software must install before reading

  1. Docker
  2. Docker-compse

Run mongo

  1. Run docker-compose.yml
docker-compose up --detach
  1. To check status replica
docker exec -it mongo_mongodb-primary_1 mongo -u root
  • Password in docker-compose.yml with MONGODB_ROOT_PASSWORD field, you can change it
  • mongo_mongodb-primary_1 it's name docker container, you can change it with field container_name in docker-compose file

After that, enter code at below to terminal docker

replicaset:PRIMARY> rs.status();

you will see all config of replica set of cluster

More

  1. That shut-down the replica set
docker-compose down
  1. Remove network if you remove images don't use docker-compose down
docker network prune
  1. Restart or rebuild
docker-compose up --detach --build

Mongo Shell

  • rs.status(): checks status of the Replica set
  • rs.initiate(): initiates set with default settings
  • rs.conf(): get the current configuration object
  • rs.add(hostportstr): add a new member to the set
  • rs.remove(hostportstr): remove a host from the replica set
  • rs.printReplicationInfo(): check oplog size and time range
  • rs.printSecondaryReplicationInfo(): check replica set members and replication lag
  • db.isMaster(): check who is primary
  • db.hello(): check who is primary

Handle when Error

  1. Every change, you must remove or edit config mongodb
  2. You should change file host
127.0.0.1 mongodb-primary
  • mongodb-primary if you change it in docker-compose.yml with MONGODB_ADVERTISED_HOSTNAME field, then you must change it's
  1. mkdir: cannot create directory '/bitnami/mongodb/data': Operation not permitted
sudo chown -R 1001 /data/mongo
  • /data/mongo:

Continue

Read file link

REF

Producer

  1. https://hub.docker.com/r/bitnami/mongodb

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published