@@ -52,11 +52,11 @@ At this point all of our nodes are up and running, but the set has yet
52
52
to be initialized. Until the set is initialized no node will become
53
53
the primary, and things are essentially "offline".
54
54
55
- To initialize the set we need to connect to a single node and run the
56
- initiate command::
55
+ To initialize the set we need to connect directly to a single node and run the
56
+ initiate command using the `` directConnection `` option ::
57
57
58
58
>>> from pymongo import MongoClient
59
- >>> c = MongoClient('localhost', 27017)
59
+ >>> c = MongoClient('localhost', 27017, directConnection=True )
60
60
61
61
.. note :: We could have connected to any of the other nodes instead,
62
62
but only the node we initiate from is allowed to contain any
@@ -81,15 +81,19 @@ The initial connection as made above is a special case for an
81
81
uninitialized replica set. Normally we'll want to connect
82
82
differently. A connection to a replica set can be made using the
83
83
:meth: `~pymongo.mongo_client.MongoClient ` constructor, specifying
84
- one or more members of the set, along with the replica set name. Any of
85
- the following connects to the replica set we just created::
84
+ one or more members of the set and optionally the replica set name.
85
+ Any of the following connects to the replica set we just created::
86
86
87
+ >>> MongoClient('localhost')
88
+ MongoClient(host=['localhost:27017'], ...)
87
89
>>> MongoClient('localhost', replicaset='foo')
88
90
MongoClient(host=['localhost:27017'], replicaset='foo', ...)
89
91
>>> MongoClient('localhost:27018', replicaset='foo')
90
92
MongoClient(['localhost:27018'], replicaset='foo', ...)
91
93
>>> MongoClient('localhost', 27019, replicaset='foo')
92
94
MongoClient(['localhost:27019'], replicaset='foo', ...)
95
+ >>> MongoClient('mongodb://localhost:27017,localhost:27018/')
96
+ MongoClient(['localhost:27017', 'localhost:27018'], ...)
93
97
>>> MongoClient('mongodb://localhost:27017,localhost:27018/?replicaSet=foo')
94
98
MongoClient(['localhost:27017', 'localhost:27018'], replicaset='foo', ...)
95
99
0 commit comments