Skip to content
Stephane Godbillon edited this page Jul 22, 2012 · 1 revision

MongoAsync provides support for Replica Sets. That means the following:

  • the driver will detect if it is connected to a Replica Set;
  • it will probe for the other nodes in the set and connect to them;
  • it will detect when the primary has changed and guess which is the new one;
  • it will allow running queries on secondaries if they are explicitely set to SlaveOk.

Connect to a Replica Set

It is very simple to connect to a Replica Set. In fact, it may not be different than connecting to a standalone server:

val connection = MongoConnection( List( "localhost:27016" ) )

The parameter list elements syntax is <hostname>[:<port>]. The port is not required. If it is not provided, the default port (27017) is inferred.

The driver will guess whether localhost:27016 is part of a Replica Set. Thus, the list of nodes given as a parameter to the MongoConnection constructor is a seed list - they are the nodes that the driver will ask for other replicas.

You may give one replica as a seed, or more, or even the whole set.

Clone this wiki locally