It is recommended that you use at least 3 instances in the replica set. Can only two be used?
No, the minimum requirement for a replica set is three processes ( docs ), but the third can be arbiter , although this is not recommended .
I have two instances and then two IP addresses. What IP should I provide to my application that will need to read / write in the database? When the database is down, how will the request be redirected to an instance that is still running?
There are two alternatives:
# 1 (recommended)
You provide a driver with all the addresses (see docs for more details), for example nodejs driver (it looks like another). Thus, the driver will know all or at least more than one of the instances directly, which will prevent problems if all of the specified instances are omitted (see # 2).
var MongoClient = require('mongodb').MongoClient; MongoClient.connect('mongodb://[server1],[server2],[...]/[database]?replicaSet=[name]', function(err, db) { });
# 2
You provide the driver with one of them (possibly primary), and mongodb will determine the rest. However, if your application starts when the specified instance does not work, the driver will not be able to find other instances and, therefore, will not be able to connect to mongodb.
Mattias
source share