Skip to content

Latest commit

 

History

History
51 lines (40 loc) · 948 Bytes

20-databases.md

File metadata and controls

51 lines (40 loc) · 948 Bytes

Databases

1. Configure MongoDB Replica Set

  • Run the following command :
$> docker exec -it db_mongo-srv0_1 mongo -u "root" --authenticationDatabase "admin" -p

# The shell is know waiting for your password
  • Create a configuration variable :
config={
  "_id":"rs0",
  "members":[
    {"_id":0"host":"mongo-srv0:27017"},
    {"_id":1,"host":"mongo-srv1:27017"},
    {"_id":2,"host":"mongo-srv2:27017"}
  ]
}
  • Initialize the Replica Set :
rs.initiate(config)
  • Create both admin as well as cluster users :
db.getSiblingDB("admin").createUser(
  {
    user: "admin",
    pwd: passwordPrompt(),
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)

db.getSiblingDB("admin").createUser(
  {
    "user" : "cluster",
    "pwd" : passwordPrompt(),
    roles: [ { "role" : "clusterAdmin", "db" : "admin" } ]
  }
)
  • Exit the container, your Replica Set is know setup.