This file is indexed.

/usr/share/doc/python-pymongo-doc/html/api/pymongo/replica_set_connection.html is in python-pymongo-doc 2.6.3-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>replica_set_connection – Tools for connecting to a MongoDB replica set &mdash; PyMongo 2.6.3 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '2.6.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/sidebar.js"></script>
    <link rel="top" title="PyMongo 2.6.3 documentation" href="../../index.html" />
    <link rel="up" title="pymongo – Python driver for MongoDB" href="index.html" />
    <link rel="next" title="son_manipulator – Manipulators that can edit SON documents as they are saved or retrieved" href="son_manipulator.html" />
    <link rel="prev" title="pool – Pool module for use with a MongoDB client." href="pool.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="son_manipulator.html" title="son_manipulator – Manipulators that can edit SON documents as they are saved or retrieved"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="pool.html" title="pool – Pool module for use with a MongoDB client."
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">PyMongo 2.6.3 documentation</a> &raquo;</li>
          <li><a href="../index.html" >API Documentation</a> &raquo;</li>
          <li><a href="index.html" accesskey="U"><tt class="docutils literal"><span class="pre">pymongo</span></tt> &#8211; Python driver for MongoDB</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-pymongo.replica_set_connection">
<span id="replica-set-connection-tools-for-connecting-to-a-mongodb-replica-set"></span><h1><tt class="xref py py-mod docutils literal"><span class="pre">replica_set_connection</span></tt> &#8211; Tools for connecting to a MongoDB replica set<a class="headerlink" href="#module-pymongo.replica_set_connection" title="Permalink to this headline"></a></h1>
<p>Tools for connecting to a MongoDB replica set.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last"><strong>DEPRECATED:</strong> Please use <a class="reference internal" href="mongo_replica_set_client.html#module-pymongo.mongo_replica_set_client" title="pymongo.mongo_replica_set_client: Tools for connecting to a MongoDB replica set"><tt class="xref py py-mod docutils literal"><span class="pre">mongo_replica_set_client</span></tt></a> instead.</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="../../examples/high_availability.html"><em>High Availability and PyMongo</em></a> for more examples of
how to connect to a replica set.</p>
</div>
<p>To get a <a class="reference internal" href="database.html#pymongo.database.Database" title="pymongo.database.Database"><tt class="xref py py-class docutils literal"><span class="pre">Database</span></tt></a> instance from a
<a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection" title="pymongo.replica_set_connection.ReplicaSetConnection"><tt class="xref py py-class docutils literal"><span class="pre">ReplicaSetConnection</span></tt></a> use either dictionary-style or
attribute-style access:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pymongo</span> <span class="kn">import</span> <span class="n">ReplicaSetConnection</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span> <span class="o">=</span> <span class="n">ReplicaSetConnection</span><span class="p">(</span><span class="s">&#39;localhost:27017&#39;</span><span class="p">,</span> <span class="n">replicaSet</span><span class="o">=</span><span class="s">&#39;repl0&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span><span class="o">.</span><span class="n">test_database</span>
<span class="go">Database(ReplicaSetConnection([u&#39;...&#39;, u&#39;...&#39;]), u&#39;test_database&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span><span class="p">[</span><span class="s">&#39;test_database&#39;</span><span class="p">]</span>
<span class="go">Database(ReplicaSetConnection([u&#39;...&#39;, u&#39;...&#39;]), u&#39;test_database&#39;)</span>
</pre></div>
</div>
<dl class="class">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection">
<em class="property">class </em><tt class="descclassname">pymongo.replica_set_connection.</tt><tt class="descname">ReplicaSetConnection</tt><big>(</big><span class="optional">[</span><em>hosts_or_uri</em><span class="optional">[</span>, <em>max_pool_size=10</em><span class="optional">[</span>, <em>document_class=dict</em><span class="optional">[</span>, <em>tz_aware=False</em><span class="optional">[</span>, <em>**kwargs</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection" title="Permalink to this definition"></a></dt>
<dd><p>Create a new connection to a MongoDB replica set.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last"><strong>DEPRECATED:</strong> <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection" title="pymongo.replica_set_connection.ReplicaSetConnection"><tt class="xref py py-class docutils literal"><span class="pre">ReplicaSetConnection</span></tt></a> is deprecated. Please
use <a class="reference internal" href="mongo_replica_set_client.html#pymongo.mongo_replica_set_client.MongoReplicaSetClient" title="pymongo.mongo_replica_set_client.MongoReplicaSetClient"><tt class="xref py py-class docutils literal"><span class="pre">MongoReplicaSetClient</span></tt></a>
instead</p>
</div>
<p>The resultant connection object has connection-pooling built
in. It also performs auto-reconnection when necessary. If an
operation fails because of a connection error,
<a class="reference internal" href="errors.html#pymongo.errors.ConnectionFailure" title="pymongo.errors.ConnectionFailure"><tt class="xref py py-class docutils literal"><span class="pre">ConnectionFailure</span></tt></a> is raised. If
auto-reconnection will be performed,
<a class="reference internal" href="errors.html#pymongo.errors.AutoReconnect" title="pymongo.errors.AutoReconnect"><tt class="xref py py-class docutils literal"><span class="pre">AutoReconnect</span></tt></a> will be
raised. Application code should handle this exception
(recognizing that the operation failed) and then continue to
execute.</p>
<p>Raises <a class="reference internal" href="errors.html#pymongo.errors.ConnectionFailure" title="pymongo.errors.ConnectionFailure"><tt class="xref py py-class docutils literal"><span class="pre">ConnectionFailure</span></tt></a> if
the connection cannot be made.</p>
<p>The <cite>hosts_or_uri</cite> parameter can be a full <a class="reference external" href="http://dochub.mongodb.org/core/connections">mongodb URI</a>, in addition to
a string of <cite>host:port</cite> pairs (e.g. &#8216;host1:port1,host2:port2&#8217;).
If <cite>hosts_or_uri</cite> is None &#8216;localhost:27017&#8217; will be used.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Instances of <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection" title="pymongo.replica_set_connection.ReplicaSetConnection"><tt class="xref py py-class docutils literal"><span class="pre">ReplicaSetConnection</span></tt></a> start a
background task to monitor the state of the replica set. This allows
it to quickly respond to changes in replica set configuration.
Before discarding an instance of <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection" title="pymongo.replica_set_connection.ReplicaSetConnection"><tt class="xref py py-class docutils literal"><span class="pre">ReplicaSetConnection</span></tt></a> make
sure you call <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection.close" title="pymongo.replica_set_connection.ReplicaSetConnection.close"><tt class="xref py py-meth docutils literal"><span class="pre">close()</span></tt></a> to ensure that the monitor task is
cleanly shut down.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><cite>hosts_or_uri</cite> (optional): A MongoDB URI or string of <cite>host:port</cite>
pairs. If a host is an IPv6 literal it must be enclosed in &#8216;[&#8216; and
&#8216;]&#8217; characters following the RFC2732 URL syntax (e.g. &#8216;[::1]&#8217; for
localhost)</li>
<li><cite>max_pool_size</cite> (optional): The maximum number of connections
each pool will open simultaneously. If this is set, operations
will block if there are <cite>max_pool_size</cite> outstanding connections
from the pool. By default the pool size is unlimited.</li>
<li><cite>document_class</cite> (optional): default class to use for
documents returned from queries on this connection</li>
<li><cite>tz_aware</cite> (optional): if <tt class="docutils literal"><span class="pre">True</span></tt>,
<tt class="xref py py-class docutils literal"><span class="pre">datetime</span></tt> instances returned as values
in a document by this <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection" title="pymongo.replica_set_connection.ReplicaSetConnection"><tt class="xref py py-class docutils literal"><span class="pre">ReplicaSetConnection</span></tt></a> will be timezone
aware (otherwise they will be naive)</li>
<li><cite>replicaSet</cite>: (required) The name of the replica set to connect to.
The driver will verify that each host it connects to is a member of
this replica set. Can be passed as a keyword argument or as a
MongoDB URI option.</li>
</ul>
<div class="line-block">
<div class="line"><strong>Other optional parameters can be passed as keyword arguments:</strong></div>
</div>
<ul class="simple">
<li><cite>host</cite>: For compatibility with connection.Connection. If both
<cite>host</cite> and <cite>hosts_or_uri</cite> are specified <cite>host</cite> takes precedence.</li>
<li><cite>port</cite>: For compatibility with connection.Connection. The default
port number to use for hosts.</li>
<li><cite>network_timeout</cite>: For compatibility with connection.Connection.
The timeout (in seconds) to use for socket operations - default
is no timeout. If both <cite>network_timeout</cite> and <cite>socketTimeoutMS</cite> are
specified <cite>network_timeout</cite> takes precedence, matching
connection.Connection.</li>
<li><cite>socketTimeoutMS</cite>: (integer) How long (in milliseconds) a send or
receive on a socket can take before timing out.</li>
<li><cite>connectTimeoutMS</cite>: (integer) How long (in milliseconds) a
connection can take to be opened before timing out.</li>
<li><cite>waitQueueTimeoutMS</cite>: (integer) How long (in milliseconds) a
thread will wait for a socket from the pool if the pool has no
free sockets. Defaults to <tt class="docutils literal"><span class="pre">None</span></tt> (no timeout).</li>
<li><cite>waitQueueMultiple</cite>: (integer) Multiplied by max_pool_size to give
the number of threads allowed to wait for a socket at one time.
Defaults to <tt class="docutils literal"><span class="pre">None</span></tt> (no waiters).</li>
<li><cite>auto_start_request</cite>: If <tt class="docutils literal"><span class="pre">True</span></tt> (the default), each thread that
accesses this <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection" title="pymongo.replica_set_connection.ReplicaSetConnection"><tt class="xref py py-class docutils literal"><span class="pre">ReplicaSetConnection</span></tt></a> has a socket allocated
to it for the thread&#8217;s lifetime, for each member of the set. For
<a class="reference internal" href="index.html#pymongo.read_preferences.ReadPreference" title="pymongo.read_preferences.ReadPreference"><tt class="xref py py-class docutils literal"><span class="pre">ReadPreference</span></tt></a> PRIMARY,
auto_start_request=True ensures consistent reads, even if you read
after an unsafe write. For read preferences other than PRIMARY,
there are no consistency guarantees.</li>
<li><cite>use_greenlets</cite>: if <tt class="docutils literal"><span class="pre">True</span></tt>, use a background Greenlet instead of
a background thread to monitor state of replica set. Additionally,
<tt class="xref py py-meth docutils literal"><span class="pre">start_request()</span></tt> will ensure that the current greenlet uses
the same socket for all operations until <tt class="xref py py-meth docutils literal"><span class="pre">end_request()</span></tt>.
<cite>use_greenlets</cite> with ReplicaSetConnection requires <a class="reference external" href="http://gevent.org/">Gevent</a> to be installed.</li>
</ul>
<div class="line-block">
<div class="line"><strong>Write Concern options:</strong></div>
</div>
<ul class="simple">
<li><cite>safe</cite>: <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection" title="pymongo.replica_set_connection.ReplicaSetConnection"><tt class="xref py py-class docutils literal"><span class="pre">ReplicaSetConnection</span></tt></a> <strong>disables</strong> acknowledgement
of write operations. Use <tt class="docutils literal"><span class="pre">safe=True</span></tt> to enable write
acknowledgement.</li>
<li><cite>w</cite>: (integer or string) Write operations will block until they have
been replicated to the specified number or tagged set of servers.
<cite>w=&lt;int&gt;</cite> always includes the replica set primary (e.g. w=3 means
write to the primary and wait until replicated to <strong>two</strong>
secondaries). Implies safe=True.</li>
<li><cite>wtimeout</cite>: (integer) Used in conjunction with <cite>w</cite>. Specify a value
in milliseconds to control how long to wait for write propagation
to complete. If replication does not complete in the given
timeframe, a timeout exception is raised. Implies safe=True.</li>
<li><cite>j</cite>: If <tt class="docutils literal"><span class="pre">True</span></tt> block until write operations have been committed
to the journal. Ignored if the server is running without journaling.
Implies safe=True.</li>
<li><cite>fsync</cite>: If <tt class="docutils literal"><span class="pre">True</span></tt> force the database to fsync all files before
returning. When used with <cite>j</cite> the server awaits the next group
commit before returning. Implies safe=True.</li>
</ul>
<div class="line-block">
<div class="line"><strong>Read preference options:</strong></div>
</div>
<ul class="simple">
<li><cite>slave_okay</cite> or <cite>slaveOk</cite> (deprecated): Use <cite>read_preference</cite>
instead.</li>
<li><cite>read_preference</cite>: The read preference for this connection.
See <a class="reference internal" href="index.html#pymongo.read_preferences.ReadPreference" title="pymongo.read_preferences.ReadPreference"><tt class="xref py py-class docutils literal"><span class="pre">ReadPreference</span></tt></a> for available</li>
<li><cite>tag_sets</cite>: Read from replica-set members with these tags.
To specify a priority-order for tag sets, provide a list of
tag sets: <tt class="docutils literal"><span class="pre">[{'dc':</span> <span class="pre">'ny'},</span> <span class="pre">{'dc':</span> <span class="pre">'la'},</span> <span class="pre">{}]</span></tt>. A final, empty tag
set, <tt class="docutils literal"><span class="pre">{}</span></tt>, means &#8220;read from any member that matches the mode,
ignoring tags.&#8221; <tt class="xref py py-class docutils literal"><span class="pre">MongoReplicaSetClient</span></tt> tries each set of
tags in turn until it finds a set of tags with at least one matching
member.</li>
<li><cite>secondary_acceptable_latency_ms</cite>: (integer) Any replica-set member
whose ping time is within secondary_acceptable_latency_ms of the
nearest member may accept reads. Default 15 milliseconds.
<strong>Ignored by mongos</strong> and must be configured on the command line.
See the <a class="reference external" href="http://docs.mongodb.org/manual/reference/mongos/#cmdoption-mongos--localThreshold">localThreshold</a> option for more information.</li>
</ul>
<div class="line-block">
<div class="line"><strong>SSL configuration:</strong></div>
</div>
<ul class="last simple">
<li><cite>ssl</cite>: If <tt class="docutils literal"><span class="pre">True</span></tt>, create the connection to the servers using SSL.</li>
<li><cite>ssl_keyfile</cite>: The private keyfile used to identify the local
connection against mongod.  If included with the <tt class="docutils literal"><span class="pre">certfile`</span> <span class="pre">then</span>
<span class="pre">only</span> <span class="pre">the</span> <span class="pre">``ssl_certfile</span></tt> is needed.  Implies <tt class="docutils literal"><span class="pre">ssl=True</span></tt>.</li>
<li><cite>ssl_certfile</cite>: The certificate file used to identify the local
connection against mongod. Implies <tt class="docutils literal"><span class="pre">ssl=True</span></tt>.</li>
<li><cite>ssl_cert_reqs</cite>: Specifies whether a certificate is required from
the other side of the connection, and whether it will be validated
if provided. It must be one of the three values <tt class="docutils literal"><span class="pre">ssl.CERT_NONE</span></tt>
(certificates ignored), <tt class="docutils literal"><span class="pre">ssl.CERT_OPTIONAL</span></tt>
(not required, but validated if provided), or <tt class="docutils literal"><span class="pre">ssl.CERT_REQUIRED</span></tt>
(required and validated). If the value of this parameter is not
<tt class="docutils literal"><span class="pre">ssl.CERT_NONE</span></tt>, then the <tt class="docutils literal"><span class="pre">ssl_ca_certs</span></tt> parameter must point
to a file of CA certificates. Implies <tt class="docutils literal"><span class="pre">ssl=True</span></tt>.</li>
<li><cite>ssl_ca_certs</cite>: The ca_certs file contains a set of concatenated
&#8220;certification authority&#8221; certificates, which are used to validate
certificates passed from the other end of the connection.
Implies <tt class="docutils literal"><span class="pre">ssl=True</span></tt>.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.5: </span>Added additional ssl options</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.3: </span>Added <cite>tag_sets</cite> and <cite>secondary_acceptable_latency_ms</cite> options.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.2: </span>Added <cite>auto_start_request</cite> and <cite>use_greenlets</cite> options.
Added support for <cite>host</cite>, <cite>port</cite>, and <cite>network_timeout</cite> keyword
arguments for compatibility with connection.Connection.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.1.</span></p>
</div>
<dl class="method">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.disconnect">
<tt class="descname">disconnect</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.disconnect" title="Permalink to this definition"></a></dt>
<dd><p>Disconnect from the replica set primary, unpin all members, and
refresh our view of the replica set.</p>
</dd></dl>

<dl class="method">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.close">
<tt class="descname">close</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.close" title="Permalink to this definition"></a></dt>
<dd><p>Close this client instance.</p>
<p>This method first terminates the replica set monitor, then disconnects
from all members of the replica set.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">This method stops the replica set monitor task. The
replica set monitor is required to properly handle replica set
configuration changes, including a failure of the primary.
Once <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection.close" title="pymongo.replica_set_connection.ReplicaSetConnection.close"><tt class="xref py py-meth docutils literal"><span class="pre">close()</span></tt></a> is called this client instance must not be reused.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.2.1: </span>The <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection.close" title="pymongo.replica_set_connection.ReplicaSetConnection.close"><tt class="xref py py-meth docutils literal"><span class="pre">close()</span></tt></a> method now terminates the replica set monitor.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.alive">
<tt class="descname">alive</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.alive" title="Permalink to this definition"></a></dt>
<dd><p>Return <tt class="docutils literal"><span class="pre">False</span></tt> if there has been an error communicating with the
primary, else <tt class="docutils literal"><span class="pre">True</span></tt>.</p>
<p>This method attempts to check the status of the primary with minimal
I/O. The current thread / greenlet retrieves a socket (its request
socket if it&#8217;s in a request, or a random idle socket if it&#8217;s not in a
request) from the primary&#8217;s connection pool and checks whether calling
<a class="reference external" href="http://docs.python.org/2/library/select.html#select.select">select</a> on it raises an error. If there are currently no idle sockets,
or if there is no known primary, <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection.alive" title="pymongo.replica_set_connection.ReplicaSetConnection.alive"><tt class="xref py py-meth docutils literal"><span class="pre">alive()</span></tt></a> will attempt to actually
find and connect to the primary.</p>
<p>A more certain way to determine primary availability is to ping it:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">client</span><span class="o">.</span><span class="n">admin</span><span class="o">.</span><span class="n">command</span><span class="p">(</span><span class="s">&#39;ping&#39;</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="describe">
<dt>
<tt class="descname">c[db_name] || c.db_name</tt></dt>
<dd><p>Get the <cite>db_name</cite> <a class="reference internal" href="database.html#pymongo.database.Database" title="pymongo.database.Database"><tt class="xref py py-class docutils literal"><span class="pre">Database</span></tt></a> on <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection" title="pymongo.replica_set_connection.ReplicaSetConnection"><tt class="xref py py-class docutils literal"><span class="pre">ReplicaSetConnection</span></tt></a> <cite>c</cite>.</p>
<p>Raises <a class="reference internal" href="errors.html#pymongo.errors.InvalidName" title="pymongo.errors.InvalidName"><tt class="xref py py-class docutils literal"><span class="pre">InvalidName</span></tt></a> if an invalid database name is used.</p>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.seeds">
<tt class="descname">seeds</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.seeds" title="Permalink to this definition"></a></dt>
<dd><p>The seed list used to connect to this replica set.</p>
<p>A sequence of (host, port) pairs.</p>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.hosts">
<tt class="descname">hosts</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.hosts" title="Permalink to this definition"></a></dt>
<dd><p>All active and passive (priority 0) replica set
members known to this client. This does not include
hidden or slaveDelay members, or arbiters.</p>
<p>A sequence of (host, port) pairs.</p>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.primary">
<tt class="descname">primary</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.primary" title="Permalink to this definition"></a></dt>
<dd><p>The (host, port) of the current primary of the replica set.</p>
<p>Returns None if there is no primary.</p>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.secondaries">
<tt class="descname">secondaries</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.secondaries" title="Permalink to this definition"></a></dt>
<dd><p>The secondary members known to this client.</p>
<p>A sequence of (host, port) pairs.</p>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.arbiters">
<tt class="descname">arbiters</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.arbiters" title="Permalink to this definition"></a></dt>
<dd><p>The arbiters known to this client.</p>
<p>A sequence of (host, port) pairs.</p>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.is_mongos">
<tt class="descname">is_mongos</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.is_mongos" title="Permalink to this definition"></a></dt>
<dd><p>If this instance is connected to mongos (always False).</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.3.</span></p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.max_pool_size">
<tt class="descname">max_pool_size</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.max_pool_size" title="Permalink to this definition"></a></dt>
<dd><p>The maximum number of sockets the pool will open concurrently.</p>
<p>When the pool has reached <cite>max_pool_size</cite>, operations block waiting for
a socket to be returned to the pool. If <tt class="docutils literal"><span class="pre">waitQueueTimeoutMS</span></tt> is set,
a blocked operation will raise <a class="reference internal" href="errors.html#pymongo.errors.ConnectionFailure" title="pymongo.errors.ConnectionFailure"><tt class="xref py py-exc docutils literal"><span class="pre">ConnectionFailure</span></tt></a>
after a timeout. By default <tt class="docutils literal"><span class="pre">waitQueueTimeoutMS</span></tt> is not set.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">SIGNIFICANT BEHAVIOR CHANGE in 2.6. Previously, this
parameter would limit only the idle sockets the pool would hold
onto, not the number of open sockets. The default has also changed
to 100.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.6.</span></p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.document_class">
<tt class="descname">document_class</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.document_class" title="Permalink to this definition"></a></dt>
<dd><p>Default class to use for documents
returned from this client.</p>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.tz_aware">
<tt class="descname">tz_aware</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.tz_aware" title="Permalink to this definition"></a></dt>
<dd><p>Does this client return timezone-aware datetimes?</p>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.max_bson_size">
<tt class="descname">max_bson_size</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.max_bson_size" title="Permalink to this definition"></a></dt>
<dd><p>Returns the maximum size BSON object the connected primary
accepts in bytes. Defaults to 4MB in server &lt; 1.7.4. Returns
0 if no primary is available.</p>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.max_message_size">
<tt class="descname">max_message_size</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.max_message_size" title="Permalink to this definition"></a></dt>
<dd><p>Returns the maximum message size the connected primary
accepts in bytes. Returns 0 if no primary is available.</p>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.auto_start_request">
<tt class="descname">auto_start_request</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.auto_start_request" title="Permalink to this definition"></a></dt>
<dd><p>Is auto_start_request enabled?</p>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.read_preference">
<tt class="descname">read_preference</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.read_preference" title="Permalink to this definition"></a></dt>
<dd><p>The read preference mode for this instance.</p>
<p>See <a class="reference internal" href="index.html#pymongo.read_preferences.ReadPreference" title="pymongo.read_preferences.ReadPreference"><tt class="xref py py-class docutils literal"><span class="pre">ReadPreference</span></tt></a> for available options.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.1.</span></p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.tag_sets">
<tt class="descname">tag_sets</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.tag_sets" title="Permalink to this definition"></a></dt>
<dd><p>Set <tt class="docutils literal"><span class="pre">tag_sets</span></tt> to a list of dictionaries like [{&#8216;dc&#8217;: &#8216;ny&#8217;}] to
read only from members whose <tt class="docutils literal"><span class="pre">dc</span></tt> tag has the value <tt class="docutils literal"><span class="pre">&quot;ny&quot;</span></tt>.
To specify a priority-order for tag sets, provide a list of
tag sets: <tt class="docutils literal"><span class="pre">[{'dc':</span> <span class="pre">'ny'},</span> <span class="pre">{'dc':</span> <span class="pre">'la'},</span> <span class="pre">{}]</span></tt>. A final, empty tag
set, <tt class="docutils literal"><span class="pre">{}</span></tt>, means &#8220;read from any member that matches the mode,
ignoring tags.&#8221; ReplicaSetConnection tries each set of tags in turn
until it finds a set of tags with at least one matching member.</p>
<blockquote>
<div><div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference external" href="http://www.mongodb.org/display/DOCS/Data+Center+Awareness">Data-Center Awareness</a></p>
</div>
</div></blockquote>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.3.</span></p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.secondary_acceptable_latency_ms">
<tt class="descname">secondary_acceptable_latency_ms</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.secondary_acceptable_latency_ms" title="Permalink to this definition"></a></dt>
<dd><p>Any replica-set member whose ping time is within
secondary_acceptable_latency_ms of the nearest member may accept
reads. Defaults to 15 milliseconds.</p>
<p>See <a class="reference internal" href="index.html#pymongo.read_preferences.ReadPreference" title="pymongo.read_preferences.ReadPreference"><tt class="xref py py-class docutils literal"><span class="pre">ReadPreference</span></tt></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.3.</span></p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><tt class="docutils literal"><span class="pre">secondary_acceptable_latency_ms</span></tt> is ignored when talking to a
replica set <em>through</em> a mongos. The equivalent is the <a class="reference external" href="http://docs.mongodb.org/manual/reference/mongos/#cmdoption-mongos--localThreshold">localThreshold</a> command
line option.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.write_concern">
<tt class="descname">write_concern</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.write_concern" title="Permalink to this definition"></a></dt>
<dd><p>The default write concern for this instance.</p>
<p>Supports dict style access for getting/setting write concern
options. Valid options include:</p>
<ul class="simple">
<li><cite>w</cite>: (integer or string) If this is a replica set, write operations
will block until they have been replicated to the specified number
or tagged set of servers. <cite>w=&lt;int&gt;</cite> always includes the replica set
primary (e.g. w=3 means write to the primary and wait until
replicated to <strong>two</strong> secondaries). <strong>Setting w=0 disables write
acknowledgement and all other write concern options.</strong></li>
<li><cite>wtimeout</cite>: (integer) Used in conjunction with <cite>w</cite>. Specify a value
in milliseconds to control how long to wait for write propagation
to complete. If replication does not complete in the given
timeframe, a timeout exception is raised.</li>
<li><cite>j</cite>: If <tt class="docutils literal"><span class="pre">True</span></tt> block until write operations have been committed
to the journal. Ignored if the server is running without journaling.</li>
<li><cite>fsync</cite>: If <tt class="docutils literal"><span class="pre">True</span></tt> force the database to fsync all files before
returning. When used with <cite>j</cite> the server awaits the next group
commit before returning.</li>
</ul>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">MongoClient</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">write_concern</span>
<span class="go">{}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">write_concern</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;w&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s">&#39;wtimeout&#39;</span><span class="p">:</span> <span class="mi">1000</span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">write_concern</span>
<span class="go">{&#39;wtimeout&#39;: 1000, &#39;w&#39;: 2}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">write_concern</span><span class="p">[</span><span class="s">&#39;j&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">write_concern</span>
<span class="go">{&#39;wtimeout&#39;: 1000, &#39;j&#39;: True, &#39;w&#39;: 2}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">write_concern</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;j&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">write_concern</span>
<span class="go">{&#39;j&#39;: True}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c"># Disable write acknowledgement and write concern</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="o">.</span><span class="n">write_concern</span><span class="p">[</span><span class="s">&#39;w&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Accessing <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection.write_concern" title="pymongo.replica_set_connection.ReplicaSetConnection.write_concern"><tt class="xref py py-attr docutils literal"><span class="pre">write_concern</span></tt></a> returns its value
(a subclass of <tt class="xref py py-class docutils literal"><span class="pre">dict</span></tt>), not a copy.</p>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">If you are using <a class="reference internal" href="connection.html#pymongo.connection.Connection" title="pymongo.connection.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a>
or <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection" title="pymongo.replica_set_connection.ReplicaSetConnection"><tt class="xref py py-class docutils literal"><span class="pre">ReplicaSetConnection</span></tt></a>
make sure you explicitly set <tt class="docutils literal"><span class="pre">w</span></tt> to 1 (or a greater value) or
<a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection.safe" title="pymongo.replica_set_connection.ReplicaSetConnection.safe"><tt class="xref py py-attr docutils literal"><span class="pre">safe</span></tt></a> to <tt class="docutils literal"><span class="pre">True</span></tt>. Unlike calling
<a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection.set_lasterror_options" title="pymongo.replica_set_connection.ReplicaSetConnection.set_lasterror_options"><tt class="xref py py-meth docutils literal"><span class="pre">set_lasterror_options()</span></tt></a>, setting an option in
<a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection.write_concern" title="pymongo.replica_set_connection.ReplicaSetConnection.write_concern"><tt class="xref py py-attr docutils literal"><span class="pre">write_concern</span></tt></a> does not implicitly set <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection.safe" title="pymongo.replica_set_connection.ReplicaSetConnection.safe"><tt class="xref py py-attr docutils literal"><span class="pre">safe</span></tt></a>
to <tt class="docutils literal"><span class="pre">True</span></tt>.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.safe">
<tt class="descname">safe</tt><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.safe" title="Permalink to this definition"></a></dt>
<dd><p><strong>DEPRECATED:</strong> Use the &#8216;w&#8217; <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection.write_concern" title="pymongo.replica_set_connection.ReplicaSetConnection.write_concern"><tt class="xref py py-attr docutils literal"><span class="pre">write_concern</span></tt></a> option instead.</p>
<p>Use getlasterror with every write operation?</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.database_names">
<tt class="descname">database_names</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.database_names" title="Permalink to this definition"></a></dt>
<dd><p>Get a list of the names of all databases on the connected server.</p>
</dd></dl>

<dl class="method">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.drop_database">
<tt class="descname">drop_database</tt><big>(</big><em>name_or_database</em><big>)</big><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.drop_database" title="Permalink to this definition"></a></dt>
<dd><p>Drop a database.</p>
<p>Raises <tt class="xref py py-class docutils literal"><span class="pre">TypeError</span></tt> if <cite>name_or_database</cite> is not an instance of
<tt class="xref py py-class docutils literal"><span class="pre">basestring</span></tt> (<tt class="xref py py-class docutils literal"><span class="pre">str</span></tt> in python 3) or Database</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><cite>name_or_database</cite>: the name of a database to drop, or a
<a class="reference internal" href="database.html#pymongo.database.Database" title="pymongo.database.Database"><tt class="xref py py-class docutils literal"><span class="pre">Database</span></tt></a> instance representing the
database to drop</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.copy_database">
<tt class="descname">copy_database</tt><big>(</big><em>from_name</em>, <em>to_name</em><span class="optional">[</span>, <em>from_host=None</em><span class="optional">[</span>, <em>username=None</em><span class="optional">[</span>, <em>password=None</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.copy_database" title="Permalink to this definition"></a></dt>
<dd><p>Copy a database, potentially from another host.</p>
<p>Raises <tt class="xref py py-class docutils literal"><span class="pre">TypeError</span></tt> if <cite>from_name</cite> or <cite>to_name</cite> is not
an instance of <tt class="xref py py-class docutils literal"><span class="pre">basestring</span></tt> (<tt class="xref py py-class docutils literal"><span class="pre">str</span></tt> in python 3).
Raises <a class="reference internal" href="errors.html#pymongo.errors.InvalidName" title="pymongo.errors.InvalidName"><tt class="xref py py-class docutils literal"><span class="pre">InvalidName</span></tt></a> if <cite>to_name</cite> is
not a valid database name.</p>
<p>If <cite>from_host</cite> is <tt class="docutils literal"><span class="pre">None</span></tt> the current host is used as the
source. Otherwise the database is copied from <cite>from_host</cite>.</p>
<p>If the source database requires authentication, <cite>username</cite> and
<cite>password</cite> must be specified.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><cite>from_name</cite>: the name of the source database</li>
<li><cite>to_name</cite>: the name of the target database</li>
<li><cite>from_host</cite> (optional): host name to copy from</li>
<li><cite>username</cite> (optional): username for source database</li>
<li><cite>password</cite> (optional): password for source database</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Specifying <cite>username</cite> and <cite>password</cite> requires server
version <strong>&gt;= 1.3.3+</strong>.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.get_default_database">
<tt class="descname">get_default_database</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.get_default_database" title="Permalink to this definition"></a></dt>
<dd><p>Get the database named in the MongoDB connection URI.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">uri</span> <span class="o">=</span> <span class="s">&#39;mongodb://host/my_database&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">client</span> <span class="o">=</span> <span class="n">MongoReplicaSetClient</span><span class="p">(</span><span class="n">uri</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">db</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_default_database</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">assert</span> <span class="n">db</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s">&#39;my_database&#39;</span>
</pre></div>
</div>
<p>Useful in scripts where you want to choose which database to use
based only on the URI in a configuration file.</p>
</dd></dl>

<dl class="method">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.close_cursor">
<tt class="descname">close_cursor</tt><big>(</big><em>cursor_id</em>, <em>_conn_id</em><big>)</big><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.close_cursor" title="Permalink to this definition"></a></dt>
<dd><p>Close a single database cursor.</p>
<p>Raises <tt class="xref py py-class docutils literal"><span class="pre">TypeError</span></tt> if <cite>cursor_id</cite> is not an instance of
<tt class="docutils literal"><span class="pre">(int,</span> <span class="pre">long)</span></tt>. What closing the cursor actually means
depends on this client&#8217;s cursor manager.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><cite>cursor_id</cite>: id of cursor to close</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.get_lasterror_options">
<tt class="descname">get_lasterror_options</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.get_lasterror_options" title="Permalink to this definition"></a></dt>
<dd><p>DEPRECATED: Use <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection.write_concern" title="pymongo.replica_set_connection.ReplicaSetConnection.write_concern"><tt class="xref py py-attr docutils literal"><span class="pre">write_concern</span></tt></a> instead.</p>
<p>Returns a dict of the getlasterror options set on this instance.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.4: </span>Deprecated get_lasterror_options.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.set_lasterror_options">
<tt class="descname">set_lasterror_options</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.set_lasterror_options" title="Permalink to this definition"></a></dt>
<dd><p>DEPRECATED: Use <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection.write_concern" title="pymongo.replica_set_connection.ReplicaSetConnection.write_concern"><tt class="xref py py-attr docutils literal"><span class="pre">write_concern</span></tt></a> instead.</p>
<p>Set getlasterror options for this instance.</p>
<p>Valid options include j=&lt;bool&gt;, w=&lt;int/string&gt;, wtimeout=&lt;int&gt;,
and fsync=&lt;bool&gt;. Implies safe=True.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last">
<li><dl class="first docutils">
<dt><cite>**kwargs</cite>: Options should be passed as keyword</dt>
<dd><p class="first last">arguments (e.g. w=2, fsync=True)</p>
</dd>
</dl>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.4: </span>Deprecated set_lasterror_options.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="pymongo.replica_set_connection.ReplicaSetConnection.unset_lasterror_options">
<tt class="descname">unset_lasterror_options</tt><big>(</big><em>*options</em><big>)</big><a class="headerlink" href="#pymongo.replica_set_connection.ReplicaSetConnection.unset_lasterror_options" title="Permalink to this definition"></a></dt>
<dd><p>DEPRECATED: Use <a class="reference internal" href="#pymongo.replica_set_connection.ReplicaSetConnection.write_concern" title="pymongo.replica_set_connection.ReplicaSetConnection.write_concern"><tt class="xref py py-attr docutils literal"><span class="pre">write_concern</span></tt></a> instead.</p>
<p>Unset getlasterror options for this instance.</p>
<p>If no options are passed unsets all getlasterror options.
This does not set <cite>safe</cite> to False.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><cite>*options</cite>: The list of options to unset.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.4: </span>Deprecated unset_lasterror_options.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.</span></p>
</div>
</dd></dl>

</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="pool.html"
                        title="previous chapter"><tt class="docutils literal"><span class="pre">pool</span></tt> &#8211; Pool module for use with a MongoDB client.</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="son_manipulator.html"
                        title="next chapter"><tt class="docutils literal"><span class="pre">son_manipulator</span></tt> &#8211; Manipulators that can edit SON documents as they are saved or retrieved</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../_sources/api/pymongo/replica_set_connection.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="son_manipulator.html" title="son_manipulator – Manipulators that can edit SON documents as they are saved or retrieved"
             >next</a> |</li>
        <li class="right" >
          <a href="pool.html" title="pool – Pool module for use with a MongoDB client."
             >previous</a> |</li>
        <li><a href="../../index.html">PyMongo 2.6.3 documentation</a> &raquo;</li>
          <li><a href="../index.html" >API Documentation</a> &raquo;</li>
          <li><a href="index.html" ><tt class="docutils literal"><span class="pre">pymongo</span></tt> &#8211; Python driver for MongoDB</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2008 - 2012, 10gen, Inc..
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.
    </div>
  </body>
</html>