Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save marcoberri/0dbab369afa69593d77b to your computer and use it in GitHub Desktop.
Save marcoberri/0dbab369afa69593d77b to your computer and use it in GitHub Desktop.
Migrate MongoDB ReplicaSet to single MongoDB Node
mongoserver:PRIMARY> rs.status();
{
"set" : "mongoserver",
"date" : ISODate("2016-02-02T10:47:07.510Z"),
"myState" : 1,
"members" : [
{
"_id" : 3,
"name" : "192.168.1.10:37017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 1195281,
"optime" : Timestamp(1454409817, 1),
"optimeDate" : ISODate("2016-02-02T10:43:37Z"),
"lastHeartbeat" : ISODate("2016-02-02T10:47:07.230Z"),
"lastHeartbeatRecv" : ISODate("2016-02-02T10:47:07.194Z"),
"pingMs" : 0,
"syncingTo" : "192.168.1.10:27017",
"configVersion" : 16
},
{
"_id" : 4,
"name" : "192.168.1.10:47017",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 1195281,
"lastHeartbeat" : ISODate("2016-02-02T10:47:06.225Z"),
"lastHeartbeatRecv" : ISODate("2016-02-02T10:47:07.238Z"),
"pingMs" : 0,
"configVersion" : 16
},
{
"_id" : 5,
"name" : "192.168.1.10:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 1195286,
"optime" : Timestamp(1454409817, 1),
"optimeDate" : ISODate("2016-02-02T10:43:37Z"),
"electionTime" : Timestamp(1453214750, 1),
"electionDate" : ISODate("2016-01-19T14:45:50Z"),
"configVersion" : 16,
"self" : true
}
],
"ok" : 1
}
##Remove Secondary
mongoserver:PRIMARY> rs.remove("192.168.1.10:37017")
{ "ok" : 1 }
mongoserver:PRIMARY> rs.remove("192.168.1.10:47017")
{ "ok" : 1 }
mongoserver:PRIMARY> rs.status();
{
"set" : "mongoserver",
"date" : ISODate("2016-02-02T10:48:23.214Z"),
"myState" : 1,
"members" : [
{
"_id" : 5,
"name" : "192.168.1.10:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 1195362,
"optime" : Timestamp(1454410079, 1),
"optimeDate" : ISODate("2016-02-02T10:47:59Z"),
"electionTime" : Timestamp(1453214750, 1),
"electionDate" : ISODate("2016-01-19T14:45:50Z"),
"configVersion" : 18,
"self" : true
}
],
"ok" : 1
}
stop all mongo service
/etc/init.d/mongod1 stop
/etc/init.d/mongod2 stop
/etc/init.d/mongod3 stop
comment replicaset info in /etc/mongod1.conf
#replication:
# replSetName: mongoserver
restart single node
/etc/init.d/mongod_single start
connect to mongo
> use local
switched to db local
> db.dropDatabase();
{ "dropped" : "local", "ok" : 1 }
restart mongo
/etc/init.d/mongod_single stop
/etc/init.d/mongod_single start
##Delete old folder data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment