/usr/share/doc/python-pymongo-doc/html/api/pymongo/mongo_client.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 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 | <!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>mongo_client – Tools for connecting to MongoDB — 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="mongo_replica_set_client – Tools for connecting to a MongoDB replica set" href="mongo_replica_set_client.html" />
<link rel="prev" title="message – Tools for creating messages to be sent to MongoDB" href="message.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="mongo_replica_set_client.html" title="mongo_replica_set_client – Tools for connecting to a MongoDB replica set"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="message.html" title="message – Tools for creating messages to be sent to MongoDB"
accesskey="P">previous</a> |</li>
<li><a href="../../index.html">PyMongo 2.6.3 documentation</a> »</li>
<li><a href="../index.html" >API Documentation</a> »</li>
<li><a href="index.html" accesskey="U"><tt class="docutils literal"><span class="pre">pymongo</span></tt> – Python driver for MongoDB</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="module-pymongo.mongo_client">
<span id="mongo-client-tools-for-connecting-to-mongodb"></span><h1><tt class="xref py py-mod docutils literal"><span class="pre">mongo_client</span></tt> – Tools for connecting to MongoDB<a class="headerlink" href="#module-pymongo.mongo_client" title="Permalink to this headline">¶</a></h1>
<p>Tools for connecting to MongoDB.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">Module <a class="reference internal" href="master_slave_connection.html#module-pymongo.master_slave_connection" title="pymongo.master_slave_connection: Master-slave connection to MongoDB"><tt class="xref py py-mod docutils literal"><span class="pre">master_slave_connection</span></tt></a> for
connecting to master-slave clusters, and
<a class="reference internal" href="../../examples/high_availability.html"><em>High Availability and PyMongo</em></a> for an example of how to connect
to a replica set, or specify a list of mongos instances for automatic
failover.</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.mongo_client.MongoClient" title="pymongo.mongo_client.MongoClient"><tt class="xref py py-class docutils literal"><span class="pre">MongoClient</span></tt></a> use either dictionary-style or attribute-style
access:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">pymongo</span> <span class="kn">import</span> <span class="n">MongoClient</span>
<span class="gp">>>> </span><span class="n">c</span> <span class="o">=</span> <span class="n">MongoClient</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">test_database</span>
<span class="go">Database(MongoClient('localhost', 27017), u'test_database')</span>
<span class="gp">>>> </span><span class="n">c</span><span class="p">[</span><span class="s">'test-database'</span><span class="p">]</span>
<span class="go">Database(MongoClient('localhost', 27017), u'test-database')</span>
</pre></div>
</div>
<dl class="class">
<dt id="pymongo.mongo_client.MongoClient">
<em class="property">class </em><tt class="descclassname">pymongo.mongo_client.</tt><tt class="descname">MongoClient</tt><big>(</big><span class="optional">[</span><em>host='localhost'</em><span class="optional">[</span>, <em>port=27017</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><span class="optional">]</span><big>)</big><a class="headerlink" href="#pymongo.mongo_client.MongoClient" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new connection to a single MongoDB instance at <em>host:port</em>.</p>
<p>The resultant client 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 <tt class="xref py py-class docutils literal"><span class="pre">TypeError</span></tt> if port is not an instance of
<tt class="docutils literal"><span class="pre">int</span></tt>. 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>host</cite> parameter can be a full <a class="reference external" href="http://dochub.mongodb.org/core/connections">mongodb URI</a>, in addition to
a simple hostname. It can also be a list of hostnames or
URIs. Any port specified in the host string(s) will override
the <cite>port</cite> parameter. If multiple mongodb URIs containing
database or auth information are passed, the last database,
username, and password present will be used. For username and
passwords reserved characters like ‘:’, ‘/’, ‘+’ and ‘@’ must be
escaped following RFC 2396.</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 simple">
<li><cite>host</cite> (optional): hostname or IP address of the
instance to connect to, or a mongodb URI, or a list of
hostnames / mongodb URIs. If <cite>host</cite> is an IPv6 literal
it must be enclosed in ‘[‘ and ‘]’ characters following
the RFC2732 URL syntax (e.g. ‘[::1]’ for localhost)</li>
<li><cite>port</cite> (optional): port number on which to connect</li>
<li><cite>max_pool_size</cite> (optional): The maximum number of connections
that the pool will open simultaneously. If this is set, operations
will block if there are <cite>max_pool_size</cite> outstanding connections
from the pool. Defaults to 100.</li>
<li><cite>document_class</cite> (optional): default class to use for
documents returned from queries on this client</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.mongo_client.MongoClient" title="pymongo.mongo_client.MongoClient"><tt class="xref py py-class docutils literal"><span class="pre">MongoClient</span></tt></a> will be timezone
aware (otherwise they will be naive)</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>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.</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.</li>
<li><cite>auto_start_request</cite>: If <tt class="docutils literal"><span class="pre">True</span></tt>, each thread that accesses
this <a class="reference internal" href="#pymongo.mongo_client.MongoClient" title="pymongo.mongo_client.MongoClient"><tt class="xref py py-class docutils literal"><span class="pre">MongoClient</span></tt></a> has a socket allocated to it for the
thread’s lifetime. This ensures consistent reads, even if you
read after an unacknowledged write. Defaults to <tt class="docutils literal"><span class="pre">False</span></tt></li>
<li><cite>use_greenlets</cite>: If <tt class="docutils literal"><span class="pre">True</span></tt>, <a class="reference internal" href="#pymongo.mongo_client.MongoClient.start_request" title="pymongo.mongo_client.MongoClient.start_request"><tt class="xref py py-meth docutils literal"><span class="pre">start_request()</span></tt></a> will ensure
that the current greenlet uses the same socket for all
operations until <a class="reference internal" href="#pymongo.mongo_client.MongoClient.end_request" title="pymongo.mongo_client.MongoClient.end_request"><tt class="xref py py-meth docutils literal"><span class="pre">end_request()</span></tt></a></li>
</ul>
<div class="line-block">
<div class="line"><strong>Write Concern options:</strong></div>
</div>
<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=<int></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). Passing w=0 <strong>disables write
acknowledgement</strong> and all other write concern options.</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="line-block">
<div class="line"><strong>Replica set keyword arguments for connecting with a replica set
- either directly or via a mongos:</strong></div>
<div class="line">(ignored by standalone mongod instances)</div>
</div>
<ul class="simple">
<li><cite>replicaSet</cite>: (string) The name of the replica set to connect to.
The driver will verify that the replica set it connects to matches
this name. Implies that the hosts specified are a seed list and the
driver should attempt to find all members of the set. <em>Ignored by
mongos</em>.</li>
<li><cite>read_preference</cite>: The read preference for this client. If
connecting to a secondary then a read preference mode <em>other</em> than
PRIMARY is required - otherwise all queries will throw
<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> “not master”.
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 all
available read preference options.</li>
<li><cite>tag_sets</cite>: Ignored unless connecting to a replica set via mongos.
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 “read from any member that matches the mode,
ignoring tags.</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 server 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
“certification authority” 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="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pymongo.mongo_client.MongoClient.end_request" title="pymongo.mongo_client.MongoClient.end_request"><tt class="xref py py-meth docutils literal"><span class="pre">end_request()</span></tt></a></p>
</div>
<div class="admonition-see-general-mongodb-documentation admonition seealso">
<p class="first admonition-title">See also</p>
<p class="admonition-title">See general MongoDB documentation</p>
<p class="last"><a class="reference external" href="http://dochub.mongodb.org/core/connections" name="pymongo.mongo_client.MongoClient"><em>connections</em></a></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.5: </span>Added additional ssl options</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.4.</span></p>
</div>
<dl class="method">
<dt id="pymongo.mongo_client.MongoClient.disconnect">
<tt class="descname">disconnect</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.mongo_client.MongoClient.disconnect" title="Permalink to this definition">¶</a></dt>
<dd><p>Disconnect from MongoDB.</p>
<p>Disconnecting will close all underlying sockets in the connection
pool. If this instance is used again it will be automatically
re-opened. Care should be taken to make sure that <a class="reference internal" href="#pymongo.mongo_client.MongoClient.disconnect" title="pymongo.mongo_client.MongoClient.disconnect"><tt class="xref py py-meth docutils literal"><span class="pre">disconnect()</span></tt></a>
is not called in the middle of a sequence of operations in which
ordering is important. This could lead to unexpected results.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pymongo.mongo_client.MongoClient.end_request" title="pymongo.mongo_client.MongoClient.end_request"><tt class="xref py py-meth docutils literal"><span class="pre">end_request()</span></tt></a></p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.3.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.mongo_client.MongoClient.close">
<tt class="descname">close</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.mongo_client.MongoClient.close" title="Permalink to this definition">¶</a></dt>
<dd><p>Alias for <a class="reference internal" href="#pymongo.mongo_client.MongoClient.disconnect" title="pymongo.mongo_client.MongoClient.disconnect"><tt class="xref py py-meth docutils literal"><span class="pre">disconnect()</span></tt></a></p>
<p>Disconnecting will close all underlying sockets in the connection
pool. If this instance is used again it will be automatically
re-opened. Care should be taken to make sure that <a class="reference internal" href="#pymongo.mongo_client.MongoClient.disconnect" title="pymongo.mongo_client.MongoClient.disconnect"><tt class="xref py py-meth docutils literal"><span class="pre">disconnect()</span></tt></a>
is not called in the middle of a sequence of operations in which
ordering is important. This could lead to unexpected results.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pymongo.mongo_client.MongoClient.end_request" title="pymongo.mongo_client.MongoClient.end_request"><tt class="xref py py-meth docutils literal"><span class="pre">end_request()</span></tt></a></p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.1.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.mongo_client.MongoClient.alive">
<tt class="descname">alive</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.mongo_client.MongoClient.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
server, else <tt class="docutils literal"><span class="pre">True</span></tt>.</p>
<p>This method attempts to check the status of the server with minimal I/O.
The current thread / greenlet retrieves a socket from the pool (its
request socket if it’s in a request, or a random idle socket if it’s not
in a request) 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, <a class="reference internal" href="#pymongo.mongo_client.MongoClient.alive" title="pymongo.mongo_client.MongoClient.alive"><tt class="xref py py-meth docutils literal"><span class="pre">alive()</span></tt></a> will
attempt to actually connect to the server.</p>
<p>A more certain way to determine server availability is:</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">'ping'</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.mongo_client.MongoClient" title="pymongo.mongo_client.MongoClient"><tt class="xref py py-class docutils literal"><span class="pre">MongoClient</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.mongo_client.MongoClient.host">
<tt class="descname">host</tt><a class="headerlink" href="#pymongo.mongo_client.MongoClient.host" title="Permalink to this definition">¶</a></dt>
<dd><p>Current connected host.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.3: </span><tt class="docutils literal"><span class="pre">host</span></tt> is now a property rather than a method.</p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.mongo_client.MongoClient.port">
<tt class="descname">port</tt><a class="headerlink" href="#pymongo.mongo_client.MongoClient.port" title="Permalink to this definition">¶</a></dt>
<dd><p>Current connected port.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.3: </span><tt class="docutils literal"><span class="pre">port</span></tt> is now a property rather than a method.</p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.mongo_client.MongoClient.is_primary">
<tt class="descname">is_primary</tt><a class="headerlink" href="#pymongo.mongo_client.MongoClient.is_primary" title="Permalink to this definition">¶</a></dt>
<dd><p>If this instance is connected to a standalone, a replica set
primary, or the master of a master-slave set.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.3.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.mongo_client.MongoClient.is_mongos">
<tt class="descname">is_mongos</tt><a class="headerlink" href="#pymongo.mongo_client.MongoClient.is_mongos" title="Permalink to this definition">¶</a></dt>
<dd><p>If this instance is connected to mongos.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.3.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.mongo_client.MongoClient.max_pool_size">
<tt class="descname">max_pool_size</tt><a class="headerlink" href="#pymongo.mongo_client.MongoClient.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>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.11.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.mongo_client.MongoClient.nodes">
<tt class="descname">nodes</tt><a class="headerlink" href="#pymongo.mongo_client.MongoClient.nodes" title="Permalink to this definition">¶</a></dt>
<dd><p>List of all known nodes.</p>
<p>Includes both nodes specified when this instance was created,
as well as nodes discovered through the replica set discovery
mechanism.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.8.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.mongo_client.MongoClient.auto_start_request">
<tt class="descname">auto_start_request</tt><a class="headerlink" href="#pymongo.mongo_client.MongoClient.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.mongo_client.MongoClient.document_class">
<tt class="descname">document_class</tt><a class="headerlink" href="#pymongo.mongo_client.MongoClient.document_class" title="Permalink to this definition">¶</a></dt>
<dd><p>Default class to use for documents
returned from this client.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.7.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.mongo_client.MongoClient.tz_aware">
<tt class="descname">tz_aware</tt><a class="headerlink" href="#pymongo.mongo_client.MongoClient.tz_aware" title="Permalink to this definition">¶</a></dt>
<dd><p>Does this client return timezone-aware datetimes?</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.8.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.mongo_client.MongoClient.max_bson_size">
<tt class="descname">max_bson_size</tt><a class="headerlink" href="#pymongo.mongo_client.MongoClient.max_bson_size" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the maximum size BSON object the connected server
accepts in bytes. Defaults to 4MB in server < 1.7.4.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.10.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.mongo_client.MongoClient.max_message_size">
<tt class="descname">max_message_size</tt><a class="headerlink" href="#pymongo.mongo_client.MongoClient.max_message_size" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the maximum message size the connected server
accepts in bytes.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.6.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.mongo_client.MongoClient.read_preference">
<tt class="descname">read_preference</tt><a class="headerlink" href="#pymongo.mongo_client.MongoClient.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.mongo_client.MongoClient.tag_sets">
<tt class="descname">tag_sets</tt><a class="headerlink" href="#pymongo.mongo_client.MongoClient.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 [{‘dc’: ‘ny’}] 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">"ny"</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 “read from any member that matches the mode,
ignoring tags.” 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.mongo_client.MongoClient.secondary_acceptable_latency_ms">
<tt class="descname">secondary_acceptable_latency_ms</tt><a class="headerlink" href="#pymongo.mongo_client.MongoClient.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.mongo_client.MongoClient.write_concern">
<tt class="descname">write_concern</tt><a class="headerlink" href="#pymongo.mongo_client.MongoClient.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=<int></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">>>> </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">>>> </span><span class="n">m</span><span class="o">.</span><span class="n">write_concern</span>
<span class="go">{}</span>
<span class="gp">>>> </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">'w'</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s">'wtimeout'</span><span class="p">:</span> <span class="mi">1000</span><span class="p">}</span>
<span class="gp">>>> </span><span class="n">m</span><span class="o">.</span><span class="n">write_concern</span>
<span class="go">{'wtimeout': 1000, 'w': 2}</span>
<span class="gp">>>> </span><span class="n">m</span><span class="o">.</span><span class="n">write_concern</span><span class="p">[</span><span class="s">'j'</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>
<span class="gp">>>> </span><span class="n">m</span><span class="o">.</span><span class="n">write_concern</span>
<span class="go">{'wtimeout': 1000, 'j': True, 'w': 2}</span>
<span class="gp">>>> </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">'j'</span><span class="p">:</span> <span class="bp">True</span><span class="p">}</span>
<span class="gp">>>> </span><span class="n">m</span><span class="o">.</span><span class="n">write_concern</span>
<span class="go">{'j': True}</span>
<span class="gp">>>> </span><span class="c"># Disable write acknowledgement and write concern</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">m</span><span class="o">.</span><span class="n">write_concern</span><span class="p">[</span><span class="s">'w'</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.mongo_client.MongoClient.write_concern" title="pymongo.mongo_client.MongoClient.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="replica_set_connection.html#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
<tt class="xref py py-attr docutils literal"><span class="pre">safe</span></tt> to <tt class="docutils literal"><span class="pre">True</span></tt>. Unlike calling
<tt class="xref py py-meth docutils literal"><span class="pre">set_lasterror_options()</span></tt>, setting an option in
<a class="reference internal" href="#pymongo.mongo_client.MongoClient.write_concern" title="pymongo.mongo_client.MongoClient.write_concern"><tt class="xref py py-attr docutils literal"><span class="pre">write_concern</span></tt></a> does not implicitly set <tt class="xref py py-attr docutils literal"><span class="pre">safe</span></tt>
to <tt class="docutils literal"><span class="pre">True</span></tt>.</p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.mongo_client.MongoClient.is_locked">
<tt class="descname">is_locked</tt><a class="headerlink" href="#pymongo.mongo_client.MongoClient.is_locked" title="Permalink to this definition">¶</a></dt>
<dd><p>Is this server locked? While locked, all write operations
are blocked, although read operations may still be allowed.
Use <a class="reference internal" href="#pymongo.mongo_client.MongoClient.unlock" title="pymongo.mongo_client.MongoClient.unlock"><tt class="xref py py-meth docutils literal"><span class="pre">unlock()</span></tt></a> to unlock.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.mongo_client.MongoClient.database_names">
<tt class="descname">database_names</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.mongo_client.MongoClient.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.mongo_client.MongoClient.drop_database">
<tt class="descname">drop_database</tt><big>(</big><em>name_or_database</em><big>)</big><a class="headerlink" href="#pymongo.mongo_client.MongoClient.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.mongo_client.MongoClient.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.mongo_client.MongoClient.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>>= 1.3.3+</strong>.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.5.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.mongo_client.MongoClient.get_default_database">
<tt class="descname">get_default_database</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.mongo_client.MongoClient.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">>>> </span><span class="n">uri</span> <span class="o">=</span> <span class="s">'mongodb://host/my_database'</span>
<span class="gp">>>> </span><span class="n">client</span> <span class="o">=</span> <span class="n">MongoClient</span><span class="p">(</span><span class="n">uri</span><span class="p">)</span>
<span class="gp">>>> </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">>>> </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">'my_database'</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.mongo_client.MongoClient.server_info">
<tt class="descname">server_info</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.mongo_client.MongoClient.server_info" title="Permalink to this definition">¶</a></dt>
<dd><p>Get information about the MongoDB server we’re connected to.</p>
</dd></dl>
<dl class="method">
<dt id="pymongo.mongo_client.MongoClient.start_request">
<tt class="descname">start_request</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.mongo_client.MongoClient.start_request" title="Permalink to this definition">¶</a></dt>
<dd><p>Ensure the current thread or greenlet always uses the same socket
until it calls <a class="reference internal" href="#pymongo.mongo_client.MongoClient.end_request" title="pymongo.mongo_client.MongoClient.end_request"><tt class="xref py py-meth docutils literal"><span class="pre">end_request()</span></tt></a>. This ensures consistent reads,
even if you read after an unacknowledged write.</p>
<p>In Python 2.6 and above, or in Python 2.5 with
“from __future__ import with_statement”, <a class="reference internal" href="#pymongo.mongo_client.MongoClient.start_request" title="pymongo.mongo_client.MongoClient.start_request"><tt class="xref py py-meth docutils literal"><span class="pre">start_request()</span></tt></a> can be
used as a context manager:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">client</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="n">auto_start_request</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">db</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">test</span>
<span class="gp">>>> </span><span class="n">_id</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">test_collection</span><span class="o">.</span><span class="n">insert</span><span class="p">({})</span>
<span class="gp">>>> </span><span class="k">with</span> <span class="n">client</span><span class="o">.</span><span class="n">start_request</span><span class="p">():</span>
<span class="gp">... </span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">100</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">db</span><span class="o">.</span><span class="n">test_collection</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s">'_id'</span><span class="p">:</span> <span class="n">_id</span><span class="p">},</span> <span class="p">{</span><span class="s">'$set'</span><span class="p">:</span> <span class="p">{</span><span class="s">'i'</span><span class="p">:</span><span class="n">i</span><span class="p">}})</span>
<span class="gp">...</span>
<span class="gp">... </span> <span class="c"># Definitely read the document after the final update completes</span>
<span class="gp">... </span> <span class="k">print</span> <span class="n">db</span><span class="o">.</span><span class="n">test_collection</span><span class="o">.</span><span class="n">find</span><span class="p">({</span><span class="s">'_id'</span><span class="p">:</span> <span class="n">_id</span><span class="p">})</span>
</pre></div>
</div>
<p>If a thread or greenlet calls start_request multiple times, an equal
number of calls to <a class="reference internal" href="#pymongo.mongo_client.MongoClient.end_request" title="pymongo.mongo_client.MongoClient.end_request"><tt class="xref py py-meth docutils literal"><span class="pre">end_request()</span></tt></a> is required to end the request.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.4: </span>Now counts the number of calls to start_request and doesn’t end
request until an equal number of calls to end_request.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.2: </span>The <a class="reference internal" href="pool.html#pymongo.pool.Request" title="pymongo.pool.Request"><tt class="xref py py-class docutils literal"><span class="pre">Request</span></tt></a> return value.
<a class="reference internal" href="#pymongo.mongo_client.MongoClient.start_request" title="pymongo.mongo_client.MongoClient.start_request"><tt class="xref py py-meth docutils literal"><span class="pre">start_request()</span></tt></a> previously returned None</p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.mongo_client.MongoClient.end_request">
<tt class="descname">end_request</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.mongo_client.MongoClient.end_request" title="Permalink to this definition">¶</a></dt>
<dd><p>Undo <a class="reference internal" href="#pymongo.mongo_client.MongoClient.start_request" title="pymongo.mongo_client.MongoClient.start_request"><tt class="xref py py-meth docutils literal"><span class="pre">start_request()</span></tt></a>. If <a class="reference internal" href="#pymongo.mongo_client.MongoClient.end_request" title="pymongo.mongo_client.MongoClient.end_request"><tt class="xref py py-meth docutils literal"><span class="pre">end_request()</span></tt></a> is called as many
times as <a class="reference internal" href="#pymongo.mongo_client.MongoClient.start_request" title="pymongo.mongo_client.MongoClient.start_request"><tt class="xref py py-meth docutils literal"><span class="pre">start_request()</span></tt></a>, the request is over and this thread’s
connection returns to the pool. Extra calls to <a class="reference internal" href="#pymongo.mongo_client.MongoClient.end_request" title="pymongo.mongo_client.MongoClient.end_request"><tt class="xref py py-meth docutils literal"><span class="pre">end_request()</span></tt></a> have
no effect.</p>
<p>Ending a request allows the <tt class="xref py py-class docutils literal"><span class="pre">socket</span></tt> that has
been reserved for this thread by <a class="reference internal" href="#pymongo.mongo_client.MongoClient.start_request" title="pymongo.mongo_client.MongoClient.start_request"><tt class="xref py py-meth docutils literal"><span class="pre">start_request()</span></tt></a> to be returned to
the pool. Other threads will then be able to re-use that
<tt class="xref py py-class docutils literal"><span class="pre">socket</span></tt>. If your application uses many threads, or has
long-running threads that infrequently perform MongoDB operations, then
judicious use of this method can lead to performance gains. Care should
be taken, however, to make sure that <a class="reference internal" href="#pymongo.mongo_client.MongoClient.end_request" title="pymongo.mongo_client.MongoClient.end_request"><tt class="xref py py-meth docutils literal"><span class="pre">end_request()</span></tt></a> is not called
in the middle of a sequence of operations in which ordering is
important. This could lead to unexpected results.</p>
</dd></dl>
<dl class="method">
<dt id="pymongo.mongo_client.MongoClient.close_cursor">
<tt class="descname">close_cursor</tt><big>(</big><em>cursor_id</em><big>)</big><a class="headerlink" href="#pymongo.mongo_client.MongoClient.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’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.mongo_client.MongoClient.kill_cursors">
<tt class="descname">kill_cursors</tt><big>(</big><em>cursor_ids</em><big>)</big><a class="headerlink" href="#pymongo.mongo_client.MongoClient.kill_cursors" title="Permalink to this definition">¶</a></dt>
<dd><p>Send a kill cursors message with the given ids.</p>
<p>Raises <tt class="xref py py-class docutils literal"><span class="pre">TypeError</span></tt> if <cite>cursor_ids</cite> is not an instance of
<tt class="docutils literal"><span class="pre">list</span></tt>.</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_ids</cite>: list of cursor ids to kill</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pymongo.mongo_client.MongoClient.set_cursor_manager">
<tt class="descname">set_cursor_manager</tt><big>(</big><em>manager_class</em><big>)</big><a class="headerlink" href="#pymongo.mongo_client.MongoClient.set_cursor_manager" title="Permalink to this definition">¶</a></dt>
<dd><p>Set this client’s cursor manager.</p>
<p>Raises <tt class="xref py py-class docutils literal"><span class="pre">TypeError</span></tt> if <cite>manager_class</cite> is not a subclass of
<a class="reference internal" href="cursor_manager.html#pymongo.cursor_manager.CursorManager" title="pymongo.cursor_manager.CursorManager"><tt class="xref py py-class docutils literal"><span class="pre">CursorManager</span></tt></a>. A cursor manager
handles closing cursors. Different managers can implement different
policies in terms of when to actually kill a cursor that has
been closed.</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>manager_class</cite>: cursor manager to use</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.1+: </span>Deprecated support for external cursor managers.</p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.mongo_client.MongoClient.fsync">
<tt class="descname">fsync</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#pymongo.mongo_client.MongoClient.fsync" title="Permalink to this definition">¶</a></dt>
<dd><p>Flush all pending writes to datafiles.</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"><p class="first">Optional parameters can be passed as keyword arguments:</p>
<ul class="simple">
<li><cite>lock</cite>: If True lock the server to disallow writes.</li>
<li><cite>async</cite>: If True don’t block while synchronizing.</li>
</ul>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last"><cite>async</cite> and <cite>lock</cite> can not be used together.</p>
</div>
<div class="last admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">MongoDB does not support the <cite>async</cite> option
on Windows and will raise an exception on that
platform.</p>
</div>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.mongo_client.MongoClient.unlock">
<tt class="descname">unlock</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.mongo_client.MongoClient.unlock" title="Permalink to this definition">¶</a></dt>
<dd><p>Unlock a previously locked server.</p>
<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="message.html"
title="previous chapter"><tt class="docutils literal"><span class="pre">message</span></tt> – Tools for creating messages to be sent to MongoDB</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="mongo_replica_set_client.html"
title="next chapter"><tt class="docutils literal"><span class="pre">mongo_replica_set_client</span></tt> – Tools for connecting to a MongoDB replica set</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../../_sources/api/pymongo/mongo_client.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="mongo_replica_set_client.html" title="mongo_replica_set_client – Tools for connecting to a MongoDB replica set"
>next</a> |</li>
<li class="right" >
<a href="message.html" title="message – Tools for creating messages to be sent to MongoDB"
>previous</a> |</li>
<li><a href="../../index.html">PyMongo 2.6.3 documentation</a> »</li>
<li><a href="../index.html" >API Documentation</a> »</li>
<li><a href="index.html" ><tt class="docutils literal"><span class="pre">pymongo</span></tt> – Python driver for MongoDB</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2008 - 2012, 10gen, Inc..
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.
</div>
</body>
</html>
|