/usr/share/doc/python-pymongo-doc/html/api/pymongo/database.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 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 | <!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>database – Database level operations — 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="collection – Collection level operations" href="collection.html" />
<link rel="prev" title="connection – Tools for connecting to MongoDB" href="connection.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="collection.html" title="collection – Collection level operations"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="connection.html" title="connection – Tools for connecting 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.database">
<span id="database-database-level-operations"></span><h1><tt class="xref py py-mod docutils literal"><span class="pre">database</span></tt> – Database level operations<a class="headerlink" href="#module-pymongo.database" title="Permalink to this headline">¶</a></h1>
<p>Database level operations.</p>
<dl class="data">
<dt id="pymongo.auth.MECHANISMS">
<tt class="descclassname">pymongo.auth.</tt><tt class="descname">MECHANISMS</tt><em class="property"> = ('GSSAPI', 'MONGODB-CR', 'MONGODB-X509', 'PLAIN')</em><a class="headerlink" href="#pymongo.auth.MECHANISMS" title="Permalink to this definition">¶</a></dt>
<dd><p>The authentication mechanisms supported by PyMongo.</p>
</dd></dl>
<dl class="data">
<dt id="pymongo.OFF">
<tt class="descclassname">pymongo.</tt><tt class="descname">OFF</tt><em class="property"> = 0</em><a class="headerlink" href="#pymongo.OFF" title="Permalink to this definition">¶</a></dt>
<dd><p>No database profiling.</p>
</dd></dl>
<dl class="data">
<dt id="pymongo.SLOW_ONLY">
<tt class="descclassname">pymongo.</tt><tt class="descname">SLOW_ONLY</tt><em class="property"> = 1</em><a class="headerlink" href="#pymongo.SLOW_ONLY" title="Permalink to this definition">¶</a></dt>
<dd><p>Only profile slow operations.</p>
</dd></dl>
<dl class="data">
<dt id="pymongo.ALL">
<tt class="descclassname">pymongo.</tt><tt class="descname">ALL</tt><em class="property"> = 2</em><a class="headerlink" href="#pymongo.ALL" title="Permalink to this definition">¶</a></dt>
<dd><p>Profile all operations.</p>
</dd></dl>
<dl class="class">
<dt id="pymongo.database.Database">
<em class="property">class </em><tt class="descclassname">pymongo.database.</tt><tt class="descname">Database</tt><big>(</big><em>connection</em>, <em>name</em><big>)</big><a class="headerlink" href="#pymongo.database.Database" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a database by connection and name.</p>
<p>Raises <tt class="xref py py-class docutils literal"><span class="pre">TypeError</span></tt> if <cite>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>name</cite> is not a valid
database name.</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>connection</cite>: a client instance</li>
<li><cite>name</cite>: database name</li>
</ul>
</td>
</tr>
</tbody>
</table>
<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/databases" name="pymongo.database.Database"><em>databases</em></a></p>
</div>
<dl class="describe">
<dt>
<tt class="descname">db[collection_name] || db.collection_name</tt></dt>
<dd><p>Get the <cite>collection_name</cite> <a class="reference internal" href="collection.html#pymongo.collection.Collection" title="pymongo.collection.Collection"><tt class="xref py py-class docutils literal"><span class="pre">Collection</span></tt></a> of
<a class="reference internal" href="#pymongo.database.Database" title="pymongo.database.Database"><tt class="xref py py-class docutils literal"><span class="pre">Database</span></tt></a> <cite>db</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 collection
name is used.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Use dictionary style access if <cite>collection_name</cite> is an
attribute of the <a class="reference internal" href="#pymongo.database.Database" title="pymongo.database.Database"><tt class="xref py py-class docutils literal"><span class="pre">Database</span></tt></a> class eg: db[<cite>collection_name</cite>].</p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.database.Database.read_preference">
<tt class="descname">read_preference</tt><a class="headerlink" href="#pymongo.database.Database.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.database.Database.tag_sets">
<tt class="descname">tag_sets</tt><a class="headerlink" href="#pymongo.database.Database.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.database.Database.secondary_acceptable_latency_ms">
<tt class="descname">secondary_acceptable_latency_ms</tt><a class="headerlink" href="#pymongo.database.Database.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.database.Database.write_concern">
<tt class="descname">write_concern</tt><a class="headerlink" href="#pymongo.database.Database.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.database.Database.write_concern" title="pymongo.database.Database.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
<a class="reference internal" href="#pymongo.database.Database.safe" title="pymongo.database.Database.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.database.Database.set_lasterror_options" title="pymongo.database.Database.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.database.Database.write_concern" title="pymongo.database.Database.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.database.Database.safe" title="pymongo.database.Database.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.database.Database.slave_okay">
<tt class="descname">slave_okay</tt><a class="headerlink" href="#pymongo.database.Database.slave_okay" title="Permalink to this definition">¶</a></dt>
<dd><p>DEPRECATED. Use <a class="reference internal" href="#pymongo.database.Database.read_preference" title="pymongo.database.Database.read_preference"><tt class="xref py py-attr docutils literal"><span class="pre">read_preference</span></tt></a> instead.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.1: </span>Deprecated slave_okay.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.database.Database.safe">
<tt class="descname">safe</tt><a class="headerlink" href="#pymongo.database.Database.safe" title="Permalink to this definition">¶</a></dt>
<dd><p><strong>DEPRECATED:</strong> Use the ‘w’ <a class="reference internal" href="#pymongo.database.Database.write_concern" title="pymongo.database.Database.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.database.Database.get_lasterror_options">
<tt class="descname">get_lasterror_options</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.database.Database.get_lasterror_options" title="Permalink to this definition">¶</a></dt>
<dd><p>DEPRECATED: Use <a class="reference internal" href="#pymongo.database.Database.write_concern" title="pymongo.database.Database.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.database.Database.set_lasterror_options">
<tt class="descname">set_lasterror_options</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#pymongo.database.Database.set_lasterror_options" title="Permalink to this definition">¶</a></dt>
<dd><p>DEPRECATED: Use <a class="reference internal" href="#pymongo.database.Database.write_concern" title="pymongo.database.Database.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=<bool>, w=<int/string>, wtimeout=<int>,
and fsync=<bool>. 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.database.Database.unset_lasterror_options">
<tt class="descname">unset_lasterror_options</tt><big>(</big><em>*options</em><big>)</big><a class="headerlink" href="#pymongo.database.Database.unset_lasterror_options" title="Permalink to this definition">¶</a></dt>
<dd><p>DEPRECATED: Use <a class="reference internal" href="#pymongo.database.Database.write_concern" title="pymongo.database.Database.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>
<dl class="method">
<dt id="pymongo.database.Database.add_son_manipulator">
<tt class="descname">add_son_manipulator</tt><big>(</big><em>manipulator</em><big>)</big><a class="headerlink" href="#pymongo.database.Database.add_son_manipulator" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a new son manipulator to this database.</p>
<p>Newly added manipulators will be applied before existing ones.</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>manipulator</cite>: the manipulator to add</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.add_user">
<tt class="descname">add_user</tt><big>(</big><em>name</em>, <em>password=None</em>, <em>read_only=None</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#pymongo.database.Database.add_user" title="Permalink to this definition">¶</a></dt>
<dd><p>Create user <cite>name</cite> with password <cite>password</cite>.</p>
<p>Add a new user with permissions for this <a class="reference internal" href="#pymongo.database.Database" title="pymongo.database.Database"><tt class="xref py py-class docutils literal"><span class="pre">Database</span></tt></a>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Will change the password if user <cite>name</cite> already exists.</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 last simple">
<li><cite>name</cite>: the name of the user to create</li>
<li><cite>password</cite> (optional): the password of the user to create. Can not
be used with the <tt class="docutils literal"><span class="pre">userSource</span></tt> argument.</li>
<li><cite>read_only</cite> (optional): if <tt class="docutils literal"><span class="pre">True</span></tt> the user will be read only</li>
<li><cite>**kwargs</cite> (optional): optional fields for the user document
(e.g. <tt class="docutils literal"><span class="pre">userSource</span></tt>, <tt class="docutils literal"><span class="pre">otherDBRoles</span></tt>, or <tt class="docutils literal"><span class="pre">roles</span></tt>). See
<a class="reference external" href="http://docs.mongodb.org/manual/reference/privilege-documents">http://docs.mongodb.org/manual/reference/privilege-documents</a>
for more information.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The use of optional keyword arguments like <tt class="docutils literal"><span class="pre">userSource</span></tt>,
<tt class="docutils literal"><span class="pre">otherDBRoles</span></tt>, or <tt class="docutils literal"><span class="pre">roles</span></tt> requires MongoDB >= 2.4.0</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.5: </span>Added kwargs support for optional fields introduced in MongoDB 2.4</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.2: </span>Added support for read only users</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.4.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.authenticate">
<tt class="descname">authenticate</tt><big>(</big><em>name</em>, <em>password=None</em>, <em>source=None</em>, <em>mechanism='MONGODB-CR'</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#pymongo.database.Database.authenticate" title="Permalink to this definition">¶</a></dt>
<dd><p>Authenticate to use this database.</p>
<p>Authentication lasts for the life of the underlying client
instance, or until <a class="reference internal" href="#pymongo.database.Database.logout" title="pymongo.database.Database.logout"><tt class="xref py py-meth docutils literal"><span class="pre">logout()</span></tt></a> is called.</p>
<p>Raises <tt class="xref py py-class docutils literal"><span class="pre">TypeError</span></tt> if (required) <cite>name</cite>, (optional) <cite>password</cite>,
or (optional) <cite>source</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).</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<ul class="last simple">
<li>This method authenticates the current connection, and
will also cause all new <tt class="xref py py-class docutils literal"><span class="pre">socket</span></tt> connections
in the underlying client instance to be authenticated automatically.</li>
<li>Authenticating more than once on the same database with different
credentials is not supported. You must call <a class="reference internal" href="#pymongo.database.Database.logout" title="pymongo.database.Database.logout"><tt class="xref py py-meth docutils literal"><span class="pre">logout()</span></tt></a> before
authenticating with new credentials.</li>
<li>When sharing a client instance between multiple threads, all
threads will share the authentication. If you need different
authentication profiles for different purposes you must use
distinct client instances.</li>
<li>To get authentication to apply immediately to all
existing sockets you may need to reset this client instance’s
sockets using <a class="reference internal" href="mongo_client.html#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>.</li>
</ul>
</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 last simple">
<li><cite>name</cite>: the name of the user to authenticate.</li>
<li><cite>password</cite> (optional): the password of the user to authenticate.
Not used with GSSAPI or MONGODB-X509 authentication.</li>
<li><cite>source</cite> (optional): the database to authenticate on. If not
specified the current database is used.</li>
<li><cite>mechanism</cite> (optional): See
<a class="reference internal" href="#pymongo.auth.MECHANISMS" title="pymongo.auth.MECHANISMS"><tt class="xref py py-data docutils literal"><span class="pre">MECHANISMS</span></tt></a> for options.
Defaults to MONGODB-CR (MongoDB Challenge Response protocol)</li>
<li><cite>gssapiServiceName</cite> (optional): Used with the GSSAPI mechanism
to specify the service name portion of the service principal name.
Defaults to ‘mongodb’.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.5: </span>Added the <cite>source</cite> and <cite>mechanism</cite> parameters. <a class="reference internal" href="#pymongo.database.Database.authenticate" title="pymongo.database.Database.authenticate"><tt class="xref py py-meth docutils literal"><span class="pre">authenticate()</span></tt></a>
now raises a subclass of <a class="reference internal" href="errors.html#pymongo.errors.PyMongoError" title="pymongo.errors.PyMongoError"><tt class="xref py py-class docutils literal"><span class="pre">PyMongoError</span></tt></a> if
authentication fails due to invalid credentials or configuration
issues.</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/authenticate" name="pymongo.database.Database.authenticate"><em>authenticate</em></a></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.collection_names">
<tt class="descname">collection_names</tt><big>(</big><em>include_system_collections=True</em><big>)</big><a class="headerlink" href="#pymongo.database.Database.collection_names" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a list of all the collection names in this 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>include_system_collections</cite> (optional): if <tt class="docutils literal"><span class="pre">False</span></tt> list
will not include system collections (e.g <tt class="docutils literal"><span class="pre">system.indexes</span></tt>)</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.command">
<tt class="descname">command</tt><big>(</big><em>command</em>, <em>value=1</em>, <em>check=True</em>, <em>allowable_errors=</em><span class="optional">[</span><span class="optional">]</span>, <em>uuid_subtype=3</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#pymongo.database.Database.command" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a MongoDB command.</p>
<p>Send command <cite>command</cite> to the database and return the
response. If <cite>command</cite> is 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) then the command {<cite>command</cite>: <cite>value</cite>}
will be sent. Otherwise, <cite>command</cite> must be an instance of
<tt class="xref py py-class docutils literal"><span class="pre">dict</span></tt> and will be sent as is.</p>
<p>Any additional keyword arguments will be added to the final
command document before it is sent.</p>
<p>For example, a command like <tt class="docutils literal"><span class="pre">{buildinfo:</span> <span class="pre">1}</span></tt> can be sent
using:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">db</span><span class="o">.</span><span class="n">command</span><span class="p">(</span><span class="s">"buildinfo"</span><span class="p">)</span>
</pre></div>
</div>
<p>For a command where the value matters, like <tt class="docutils literal"><span class="pre">{collstats:</span>
<span class="pre">collection_name}</span></tt> we can do:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">db</span><span class="o">.</span><span class="n">command</span><span class="p">(</span><span class="s">"collstats"</span><span class="p">,</span> <span class="n">collection_name</span><span class="p">)</span>
</pre></div>
</div>
<p>For commands that take additional arguments we can use
kwargs. So <tt class="docutils literal"><span class="pre">{filemd5:</span> <span class="pre">object_id,</span> <span class="pre">root:</span> <span class="pre">file_root}</span></tt> becomes:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">db</span><span class="o">.</span><span class="n">command</span><span class="p">(</span><span class="s">"filemd5"</span><span class="p">,</span> <span class="n">object_id</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="n">file_root</span><span class="p">)</span>
</pre></div>
</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 last">
<li><p class="first"><cite>command</cite>: document representing the command to be issued,
or the name of the command (for simple commands only).</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">the order of keys in the <cite>command</cite> document is
significant (the “verb” must come first), so commands
which require multiple keys (e.g. <cite>findandmodify</cite>)
should use an instance of <a class="reference internal" href="../bson/son.html#bson.son.SON" title="bson.son.SON"><tt class="xref py py-class docutils literal"><span class="pre">SON</span></tt></a> or
a string and kwargs instead of a Python <cite>dict</cite>.</p>
</div>
</li>
<li><p class="first"><cite>value</cite> (optional): value to use for the command verb when
<cite>command</cite> is passed as a string</p>
</li>
<li><p class="first"><cite>check</cite> (optional): check the response for errors, raising
<a class="reference internal" href="errors.html#pymongo.errors.OperationFailure" title="pymongo.errors.OperationFailure"><tt class="xref py py-class docutils literal"><span class="pre">OperationFailure</span></tt></a> if there are any</p>
</li>
<li><p class="first"><cite>allowable_errors</cite>: if <cite>check</cite> is <tt class="docutils literal"><span class="pre">True</span></tt>, error messages
in this list will be ignored by error-checking</p>
</li>
<li><p class="first"><cite>uuid_subtype</cite> (optional): The BSON binary subtype to use
for a UUID used in this command.</p>
</li>
<li><p class="first"><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
options.</p>
</li>
<li><p class="first"><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 “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>
</li>
<li><p class="first"><cite>secondary_acceptable_latency_ms</cite>: 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.</p>
</li>
<li><p class="first"><cite>**kwargs</cite> (optional): additional keyword arguments will
be added to the command document before it is sent</p>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><tt class="docutils literal"><span class="pre">command</span></tt> ignores the <tt class="docutils literal"><span class="pre">network_timeout</span></tt> parameter.</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 support for <cite>as_class</cite> - the class you want to use for
the resulting documents</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.6: </span>Added the <cite>value</cite> argument for string commands, and keyword
arguments for additional command options.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.5: </span><cite>command</cite> can be a string in addition to a full document.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.4.</span></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/commands" name="pymongo.database.Database.command"><em>commands</em></a></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.database.Database.connection">
<tt class="descname">connection</tt><a class="headerlink" href="#pymongo.database.Database.connection" title="Permalink to this definition">¶</a></dt>
<dd><p>The client instance for this <a class="reference internal" href="#pymongo.database.Database" title="pymongo.database.Database"><tt class="xref py py-class docutils literal"><span class="pre">Database</span></tt></a>.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.3: </span><tt class="docutils literal"><span class="pre">connection</span></tt> is now a property rather than a method.</p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.create_collection">
<tt class="descname">create_collection</tt><big>(</big><em>name</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#pymongo.database.Database.create_collection" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new <a class="reference internal" href="collection.html#pymongo.collection.Collection" title="pymongo.collection.Collection"><tt class="xref py py-class docutils literal"><span class="pre">Collection</span></tt></a> in this
database.</p>
<p>Normally collection creation is automatic. This method should
only be used to specify options on
creation. <a class="reference internal" href="errors.html#pymongo.errors.CollectionInvalid" title="pymongo.errors.CollectionInvalid"><tt class="xref py py-class docutils literal"><span class="pre">CollectionInvalid</span></tt></a> will be
raised if the collection already exists.</p>
<p>Options should be passed as keyword arguments to this
method. Any of the following options are valid:</p>
<blockquote>
<div><ul class="simple">
<li>“size”: desired initial size for the collection (in
bytes). For capped collections this size is the max
size of the collection.</li>
<li>“capped”: if True, this is a capped collection</li>
<li>“max”: maximum number of objects if capped (optional)</li>
</ul>
</div></blockquote>
<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</cite>: the name of the collection to create</li>
<li><cite>**kwargs</cite> (optional): additional keyword arguments will
be passed as options for the create collection command</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.2: </span>Removed deprecated argument: options</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.5: </span>deprecating <cite>options</cite> in favor of kwargs</p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.current_op">
<tt class="descname">current_op</tt><big>(</big><em>include_all=False</em><big>)</big><a class="headerlink" href="#pymongo.database.Database.current_op" title="Permalink to this definition">¶</a></dt>
<dd><p>Get information on operations currently running.</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>include_all</cite> (optional): if <tt class="docutils literal"><span class="pre">True</span></tt> also list currently
idle operations in the result</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.dereference">
<tt class="descname">dereference</tt><big>(</big><em>dbref</em><big>)</big><a class="headerlink" href="#pymongo.database.Database.dereference" title="Permalink to this definition">¶</a></dt>
<dd><p>Dereference a <a class="reference internal" href="../bson/dbref.html#bson.dbref.DBRef" title="bson.dbref.DBRef"><tt class="xref py py-class docutils literal"><span class="pre">DBRef</span></tt></a>, getting the
document it points to.</p>
<p>Raises <tt class="xref py py-class docutils literal"><span class="pre">TypeError</span></tt> if <cite>dbref</cite> is not an instance of
<a class="reference internal" href="../bson/dbref.html#bson.dbref.DBRef" title="bson.dbref.DBRef"><tt class="xref py py-class docutils literal"><span class="pre">DBRef</span></tt></a>. Returns a document, or <tt class="docutils literal"><span class="pre">None</span></tt> if
the reference does not point to a valid document. Raises
<tt class="xref py py-class docutils literal"><span class="pre">ValueError</span></tt> if <cite>dbref</cite> has a database specified that
is different from the current 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>dbref</cite>: the reference</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.drop_collection">
<tt class="descname">drop_collection</tt><big>(</big><em>name_or_collection</em><big>)</big><a class="headerlink" href="#pymongo.database.Database.drop_collection" title="Permalink to this definition">¶</a></dt>
<dd><p>Drop a collection.</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_collection</cite>: the name of a collection to drop or the
collection object itself</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.error">
<tt class="descname">error</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.database.Database.error" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a database error if one occured on the last operation.</p>
<p>Return None if the last operation was error-free. Otherwise return the
error that occurred.</p>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.eval">
<tt class="descname">eval</tt><big>(</big><em>code</em>, <em>*args</em><big>)</big><a class="headerlink" href="#pymongo.database.Database.eval" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluate a JavaScript expression in MongoDB.</p>
<p>Useful if you need to touch a lot of data lightly; in such a
scenario the network transfer of the data could be a
bottleneck. The <cite>code</cite> argument must be a JavaScript
function. Additional positional arguments will be passed to
that function when it is run on the server.</p>
<p>Raises <tt class="xref py py-class docutils literal"><span class="pre">TypeError</span></tt> if <cite>code</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 <cite>Code</cite>.
Raises <a class="reference internal" href="errors.html#pymongo.errors.OperationFailure" title="pymongo.errors.OperationFailure"><tt class="xref py py-class docutils literal"><span class="pre">OperationFailure</span></tt></a> if the eval
fails. Returns the result of the evaluation.</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>code</cite>: string representation of JavaScript code to be
evaluated</li>
<li><cite>args</cite> (optional): additional positional arguments are
passed to the <cite>code</cite> being evaluated</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.database.Database.incoming_copying_manipulators">
<tt class="descname">incoming_copying_manipulators</tt><a class="headerlink" href="#pymongo.database.Database.incoming_copying_manipulators" title="Permalink to this definition">¶</a></dt>
<dd><p>List all incoming SON copying manipulators
installed on this instance.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.database.Database.incoming_manipulators">
<tt class="descname">incoming_manipulators</tt><a class="headerlink" href="#pymongo.database.Database.incoming_manipulators" title="Permalink to this definition">¶</a></dt>
<dd><p>List all incoming SON manipulators
installed on this instance.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.last_status">
<tt class="descname">last_status</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.database.Database.last_status" title="Permalink to this definition">¶</a></dt>
<dd><p>Get status information from the last operation.</p>
<p>Returns a SON object with status information.</p>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.logout">
<tt class="descname">logout</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.database.Database.logout" title="Permalink to this definition">¶</a></dt>
<dd><p>Deauthorize use of this database for this client instance.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Other databases may still be authenticated, and other
existing <tt class="xref py py-class docutils literal"><span class="pre">socket</span></tt> connections may remain
authenticated for this database unless you reset all sockets
with <a class="reference internal" href="mongo_client.html#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>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.database.Database.name">
<tt class="descname">name</tt><a class="headerlink" href="#pymongo.database.Database.name" title="Permalink to this definition">¶</a></dt>
<dd><p>The name of this <a class="reference internal" href="#pymongo.database.Database" title="pymongo.database.Database"><tt class="xref py py-class docutils literal"><span class="pre">Database</span></tt></a>.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.3: </span><tt class="docutils literal"><span class="pre">name</span></tt> is now a property rather than a method.</p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.database.Database.outgoing_copying_manipulators">
<tt class="descname">outgoing_copying_manipulators</tt><a class="headerlink" href="#pymongo.database.Database.outgoing_copying_manipulators" title="Permalink to this definition">¶</a></dt>
<dd><p>List all outgoing SON copying manipulators
installed on this instance.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.database.Database.outgoing_manipulators">
<tt class="descname">outgoing_manipulators</tt><a class="headerlink" href="#pymongo.database.Database.outgoing_manipulators" title="Permalink to this definition">¶</a></dt>
<dd><p>List all outgoing SON manipulators
installed on this instance.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.previous_error">
<tt class="descname">previous_error</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.database.Database.previous_error" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the most recent error to have occurred on this database.</p>
<p>Only returns errors that have occurred since the last call to
<cite>Database.reset_error_history</cite>. Returns None if no such errors have
occurred.</p>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.profiling_info">
<tt class="descname">profiling_info</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.database.Database.profiling_info" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list containing current profiling information.</p>
<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/profiling" name="pymongo.database.Database.profiling_info"><em>profiling</em></a></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.profiling_level">
<tt class="descname">profiling_level</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.database.Database.profiling_level" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the database’s current profiling level.</p>
<p>Returns one of (<a class="reference internal" href="#pymongo.OFF" title="pymongo.OFF"><tt class="xref py py-data docutils literal"><span class="pre">OFF</span></tt></a>,
<a class="reference internal" href="#pymongo.SLOW_ONLY" title="pymongo.SLOW_ONLY"><tt class="xref py py-data docutils literal"><span class="pre">SLOW_ONLY</span></tt></a>, <a class="reference internal" href="#pymongo.ALL" title="pymongo.ALL"><tt class="xref py py-data docutils literal"><span class="pre">ALL</span></tt></a>).</p>
<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/profiling" name="pymongo.database.Database.profiling_level"><em>profiling</em></a></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.remove_user">
<tt class="descname">remove_user</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#pymongo.database.Database.remove_user" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove user <cite>name</cite> from this <a class="reference internal" href="#pymongo.database.Database" title="pymongo.database.Database"><tt class="xref py py-class docutils literal"><span class="pre">Database</span></tt></a>.</p>
<p>User <cite>name</cite> will no longer have permissions to access this
<a class="reference internal" href="#pymongo.database.Database" title="pymongo.database.Database"><tt class="xref py py-class docutils literal"><span class="pre">Database</span></tt></a>.</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</cite>: the name of the user to remove</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.4.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.reset_error_history">
<tt class="descname">reset_error_history</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.database.Database.reset_error_history" title="Permalink to this definition">¶</a></dt>
<dd><p>Reset the error history of this database.</p>
<p>Calls to <cite>Database.previous_error</cite> will only return errors that have
occurred since the most recent call to this method.</p>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.set_profiling_level">
<tt class="descname">set_profiling_level</tt><big>(</big><em>level</em>, <em>slow_ms=None</em><big>)</big><a class="headerlink" href="#pymongo.database.Database.set_profiling_level" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the database’s profiling level.</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>level</cite>: Specifies a profiling level, see list of possible values
below.</li>
<li><cite>slow_ms</cite>: Optionally modify the threshold for the profile to
consider a query or operation. Even if the profiler is off queries
slower than the <cite>slow_ms</cite> level will get written to the logs.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Possible <cite>level</cite> values:</p>
<table border="1" class="docutils">
<colgroup>
<col width="44%" />
<col width="56%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Level</th>
<th class="head">Setting</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><a class="reference internal" href="#pymongo.OFF" title="pymongo.OFF"><tt class="xref py py-data docutils literal"><span class="pre">OFF</span></tt></a></td>
<td>Off. No profiling.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#pymongo.SLOW_ONLY" title="pymongo.SLOW_ONLY"><tt class="xref py py-data docutils literal"><span class="pre">SLOW_ONLY</span></tt></a></td>
<td>On. Only includes slow operations.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#pymongo.ALL" title="pymongo.ALL"><tt class="xref py py-data docutils literal"><span class="pre">ALL</span></tt></a></td>
<td>On. Includes all operations.</td>
</tr>
</tbody>
</table>
<p>Raises <tt class="xref py py-class docutils literal"><span class="pre">ValueError</span></tt> if level is not one of
(<a class="reference internal" href="#pymongo.OFF" title="pymongo.OFF"><tt class="xref py py-data docutils literal"><span class="pre">OFF</span></tt></a>, <a class="reference internal" href="#pymongo.SLOW_ONLY" title="pymongo.SLOW_ONLY"><tt class="xref py py-data docutils literal"><span class="pre">SLOW_ONLY</span></tt></a>,
<a class="reference internal" href="#pymongo.ALL" title="pymongo.ALL"><tt class="xref py py-data docutils literal"><span class="pre">ALL</span></tt></a>).</p>
<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/profiling" name="pymongo.database.Database.set_profiling_level"><em>profiling</em></a></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.database.Database.system_js">
<tt class="descname">system_js</tt><a class="headerlink" href="#pymongo.database.Database.system_js" title="Permalink to this definition">¶</a></dt>
<dd><p>A <a class="reference internal" href="#pymongo.database.SystemJS" title="pymongo.database.SystemJS"><tt class="xref py py-class docutils literal"><span class="pre">SystemJS</span></tt></a> helper for this <a class="reference internal" href="#pymongo.database.Database" title="pymongo.database.Database"><tt class="xref py py-class docutils literal"><span class="pre">Database</span></tt></a>.</p>
<p>See the documentation for <a class="reference internal" href="#pymongo.database.SystemJS" title="pymongo.database.SystemJS"><tt class="xref py py-class docutils literal"><span class="pre">SystemJS</span></tt></a> for more details.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.5.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.database.Database.validate_collection">
<tt class="descname">validate_collection</tt><big>(</big><em>name_or_collection</em>, <em>scandata=False</em>, <em>full=False</em><big>)</big><a class="headerlink" href="#pymongo.database.Database.validate_collection" title="Permalink to this definition">¶</a></dt>
<dd><p>Validate a collection.</p>
<p>Returns a dict of validation info. Raises CollectionInvalid if
validation fails.</p>
<p>With MongoDB < 1.9 the result dict will include a <cite>result</cite> key
with a string value that represents the validation results. With
MongoDB >= 1.9 the <cite>result</cite> key no longer exists and the results
are split into individual fields in the result dict.</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_collection</cite>: A Collection object or the name of a
collection to validate.</li>
<li><cite>scandata</cite>: Do extra checks beyond checking the overall
structure of the collection.</li>
<li><cite>full</cite>: Have the server do a more thorough scan of the
collection. Use with <cite>scandata</cite> for a thorough scan
of the structure of the collection and the individual
documents. Ignored in MongoDB versions before 1.9.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.11: </span>validate_collection previously returned a string.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.11: </span>Added <cite>scandata</cite> and <cite>full</cite> options.</p>
</div>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="pymongo.database.SystemJS">
<em class="property">class </em><tt class="descclassname">pymongo.database.</tt><tt class="descname">SystemJS</tt><big>(</big><em>database</em><big>)</big><a class="headerlink" href="#pymongo.database.SystemJS" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a system js helper for the database <cite>database</cite>.</p>
<p>An instance of <a class="reference internal" href="#pymongo.database.SystemJS" title="pymongo.database.SystemJS"><tt class="xref py py-class docutils literal"><span class="pre">SystemJS</span></tt></a> can be created with an instance
of <a class="reference internal" href="#pymongo.database.Database" title="pymongo.database.Database"><tt class="xref py py-class docutils literal"><span class="pre">Database</span></tt></a> through <a class="reference internal" href="#pymongo.database.Database.system_js" title="pymongo.database.Database.system_js"><tt class="xref py py-attr docutils literal"><span class="pre">Database.system_js</span></tt></a>,
manual instantiation of this class should not be necessary.</p>
<p><a class="reference internal" href="#pymongo.database.SystemJS" title="pymongo.database.SystemJS"><tt class="xref py py-class docutils literal"><span class="pre">SystemJS</span></tt></a> instances allow for easy manipulation and
access to server-side JavaScript:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">db</span><span class="o">.</span><span class="n">system_js</span><span class="o">.</span><span class="n">add1</span> <span class="o">=</span> <span class="s">"function (x) { return x + 1; }"</span>
<span class="gp">>>> </span><span class="n">db</span><span class="o">.</span><span class="n">system</span><span class="o">.</span><span class="n">js</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="s">"add1"</span><span class="p">})</span><span class="o">.</span><span class="n">count</span><span class="p">()</span>
<span class="go">1</span>
<span class="gp">>>> </span><span class="n">db</span><span class="o">.</span><span class="n">system_js</span><span class="o">.</span><span class="n">add1</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="go">6.0</span>
<span class="gp">>>> </span><span class="k">del</span> <span class="n">db</span><span class="o">.</span><span class="n">system_js</span><span class="o">.</span><span class="n">add1</span>
<span class="gp">>>> </span><span class="n">db</span><span class="o">.</span><span class="n">system</span><span class="o">.</span><span class="n">js</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="s">"add1"</span><span class="p">})</span><span class="o">.</span><span class="n">count</span><span class="p">()</span>
<span class="go">0</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Requires server version <strong>>= 1.1.1</strong></p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.5.</span></p>
</div>
<dl class="method">
<dt id="pymongo.database.SystemJS.list">
<tt class="descname">list</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.database.SystemJS.list" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a list of the names of the functions stored in this database.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.9.</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="connection.html"
title="previous chapter"><tt class="docutils literal"><span class="pre">connection</span></tt> – Tools for connecting to MongoDB</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="collection.html"
title="next chapter"><tt class="docutils literal"><span class="pre">collection</span></tt> – Collection level operations</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../../_sources/api/pymongo/database.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="collection.html" title="collection – Collection level operations"
>next</a> |</li>
<li class="right" >
<a href="connection.html" title="connection – Tools for connecting 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>
|