- show dbs
test
test1
- db
test
- db.getSisterDB('test1').collection.count()
123
Wednesday, March 26, 2014
Mongo 2.4.9 - connect
- var c = connect('localhost:27002/database')
- db
- show dbs
- c.isMaster()
- c.getMongo().setSlaveOk()
- c.colleciont.count()
- c.collection.find().limit(3)
- db
- show dbs
- c.isMaster()
- c.getMongo().setSlaveOk()
- c.colleciont.count()
- c.collection.find().limit(3)
Monday, March 24, 2014
MongoDB 2.4 - Replica Set for Testing and Developing
1. start a single mongod as a standalone server
- cd
- mkdir 1
- mongod --dbpath 1 --port 27001 --smallfiles --oplogSize 50 --logpath 1.log --logappend --fork
- mongo --port 27001
2. convert the mongod instance to a single server replica set
- exit
- killall mongod
- mongod --replSet rstest --dbpath 1 --port 27001 --smallfiles --oplogSize 50 --logpath 1.log --logappend --fork
- mongo --port 27001
- Note: use hostname command to check hostname of the server
-
cfg =
{
"_id" : "rstest",
"members" : [
{
"_id" : 0,
"host" : "localhost:27001"
}
]
}
- rs.initiate(cfg)
3. add two more members to the set
- exit
- cd
- mkdir 2 3
- mongod --replSet rstest --dbpath 2 --port 27002 --smallfiles --oplogSize 50 --logpath 2.log --logappend --fork
- mongod --replSet rstest --dbpath 3 --port 27003 --smallfiles --oplogSize 50 --logpath 3.log --logappend --fork
- mongo --port 27001
3.1.
- cfg = rs.conf()
- cfg.members[1] = { "_id" : 1, "host" : "localhost:27002" }
- cfg.members[2] = { "_id" : 2, "host" : "localhost:27003" }
- rs.reconfig(cfg)
3.2.
- rs.add('localhost:27002')
- rs.add('localhost:27003')
4. retire the first member from the set
- rs.stepDown(300)
- exit
- terminate mongod process for memeber 1
- go to the new primary of the set
- cfg = rs.conf()
- cfg.members.shift()
- rs.reconfig(cfg)
- cd
- mkdir 1
- mongod --dbpath 1 --port 27001 --smallfiles --oplogSize 50 --logpath 1.log --logappend --fork
- mongo --port 27001
2. convert the mongod instance to a single server replica set
- exit
- killall mongod
- mongod --replSet rstest --dbpath 1 --port 27001 --smallfiles --oplogSize 50 --logpath 1.log --logappend --fork
- mongo --port 27001
- Note: use hostname command to check hostname of the server
-
cfg =
{
"_id" : "rstest",
"members" : [
{
"_id" : 0,
"host" : "localhost:27001"
}
]
}
- rs.initiate(cfg)
3. add two more members to the set
- exit
- cd
- mkdir 2 3
- mongod --replSet rstest --dbpath 2 --port 27002 --smallfiles --oplogSize 50 --logpath 2.log --logappend --fork
- mongod --replSet rstest --dbpath 3 --port 27003 --smallfiles --oplogSize 50 --logpath 3.log --logappend --fork
- mongo --port 27001
3.1.
- cfg = rs.conf()
- cfg.members[1] = { "_id" : 1, "host" : "localhost:27002" }
- cfg.members[2] = { "_id" : 2, "host" : "localhost:27003" }
- rs.reconfig(cfg)
3.2.
- rs.add('localhost:27002')
- rs.add('localhost:27003')
4. retire the first member from the set
- rs.stepDown(300)
- exit
- terminate mongod process for memeber 1
- go to the new primary of the set
- cfg = rs.conf()
- cfg.members.shift()
- rs.reconfig(cfg)
Subscribe to:
Posts (Atom)