Skip to content

Instantly share code, notes, and snippets.

@bootandy
Last active November 6, 2019 23:10
Show Gist options
  • Select an option

  • Save bootandy/4134840 to your computer and use it in GitHub Desktop.

Select an option

Save bootandy/4134840 to your computer and use it in GitHub Desktop.
Mongodb admin notes
Start mongodb replica servers:
mongod --replSet abc --dbpath /db/1 --port 27001 --oplogSize 50 --logpath log.1 --logappend --fork --rest
mongod --replSet abc --dbpath /db/2 --port 27002 --oplogSize 50 --logpath log.2 --logappend --fork --rest
mongod --replSet abc --dbpath /db/3 --port 27003 --oplogSize 50 --logpath log.3 --logappend --fork --rest
Basic config for a replica set:
cfg=
{
"_id" : "abc",
"version" : 1,
"members" : [
{
"_id" : 0,
"host" : "localhost:27001"
},
{
"_id" : 1,
"host" : "localhost:27002"
},
{
"_id" : 2,
"host" : "localhost:27003",
}
]
}
rs.initiate(cfg)
[ rs.reconfig(cfg) ]
options: store arbiterOnly / priority / hidden / slaveDelay / (votes)
priority - how likely it will be master (0=never)
slaveDelay - db which is X seconds delayed (requires big oplog, priority always 0)
Run commands on slave:
rs.slaveOk()
Check on things:
>rs.status()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment