I have 3 servers all running Mongo as a replica set, 1 Primary and 2 Replicas.
If one should fail, my auto scale will kill the instance and restart the server using user data to reinstall the packages.
How can i notify the primary (new or old) that the instance has come back to life as it will have a new private ip address (you can't assign static private ip's to autoscale/launch config)
I can't seem to find a way in either Mongoose or recent versions of the Mongo Node Driver to tell the primary there is a new instance that wants to join.
I can do this manually by accessing the Mongo shell and passing in
rs0:PRIMARY> rs.add("10.23.229.17");
It will be added, and the data will sync. But how can I do rs.add through the node driver or Bash script?
update
I found this post pretty useful, Can I call rs.initiate() and rs.Add() from node.js using the MongoDb driver?
basically, this is a list of all database commands. Though I can't find anything that wraps these well, it's easy enough to do it using the command method:
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://10.23.223.231', function(err, db) {
if (err) {
console.log('error', err);
}
else {
var adminDb = db.admin();
//use any command from https://goo.gl/0oh6H5
adminDb.command({ replSetGetConfig: 1 }, function(err, info) {
if (!eer) { console.log(info); }
});
}
});