/usr/share/doc/python-pymongo-doc/html/api/pymongo/cursor.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 | <!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>cursor – Tools for iterating over MongoDB query results — 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="errors – Exceptions raised by the pymongo package" href="errors.html" />
<link rel="prev" title="collection – Collection level operations" href="collection.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="errors.html" title="errors – Exceptions raised by the pymongo package"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="collection.html" title="collection – Collection level operations"
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.cursor">
<span id="cursor-tools-for-iterating-over-mongodb-query-results"></span><h1><tt class="xref py py-mod docutils literal"><span class="pre">cursor</span></tt> – Tools for iterating over MongoDB query results<a class="headerlink" href="#module-pymongo.cursor" title="Permalink to this headline">¶</a></h1>
<p>Cursor class to iterate over Mongo query results.</p>
<dl class="class">
<dt id="pymongo.cursor.Cursor">
<em class="property">class </em><tt class="descclassname">pymongo.cursor.</tt><tt class="descname">Cursor</tt><big>(</big><em>collection, spec=None, fields=None, skip=0, limit=0, timeout=True, snapshot=False, tailable=False, sort=None, max_scan=None, as_class=None, slave_okay=False, await_data=False, partial=False, manipulate=True, read_preference=ReadPreference.PRIMARY, tag_sets=[{}], secondary_acceptable_latency_ms=None, exhaust=False, network_timeout=None</em><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new cursor.</p>
<p>Should not be called directly by application developers - see
<a class="reference internal" href="collection.html#pymongo.collection.Collection.find" title="pymongo.collection.Collection.find"><tt class="xref py py-meth docutils literal"><span class="pre">find()</span></tt></a> instead.</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/cursors" name="pymongo.cursor.Cursor"><em>cursors</em></a></p>
</div>
<dl class="describe">
<dt>
<tt class="descname">c[index]</tt></dt>
<dd><p>See <a class="reference internal" href="#pymongo.cursor.Cursor.__getitem__" title="pymongo.cursor.Cursor.__getitem__"><tt class="xref py py-meth docutils literal"><span class="pre">__getitem__()</span></tt></a>.</p>
</dd></dl>
<dl class="method">
<dt id="pymongo.cursor.Cursor.__getitem__">
<tt class="descname">__getitem__</tt><big>(</big><em>index</em><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor.__getitem__" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a single document or a slice of documents from this cursor.</p>
<p>Raises <a class="reference internal" href="errors.html#pymongo.errors.InvalidOperation" title="pymongo.errors.InvalidOperation"><tt class="xref py py-class docutils literal"><span class="pre">InvalidOperation</span></tt></a> if this
cursor has already been used.</p>
<p>To get a single document use an integral index, e.g.:</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">test</span><span class="o">.</span><span class="n">find</span><span class="p">()[</span><span class="mi">50</span><span class="p">]</span>
</pre></div>
</div>
<p>An <tt class="xref py py-class docutils literal"><span class="pre">IndexError</span></tt> will be raised if the index is negative
or greater than the amount of documents in this cursor. Any
limit previously applied to this cursor will be ignored.</p>
<p>To get a slice of documents use a slice index, e.g.:</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">test</span><span class="o">.</span><span class="n">find</span><span class="p">()[</span><span class="mi">20</span><span class="p">:</span><span class="mi">25</span><span class="p">]</span>
</pre></div>
</div>
<p>This will return this cursor with a limit of <tt class="docutils literal"><span class="pre">5</span></tt> and skip of
<tt class="docutils literal"><span class="pre">20</span></tt> applied. Using a slice index will override any prior
limits or skips applied to this cursor (including those
applied through previous calls to this method). Raises
<tt class="xref py py-class docutils literal"><span class="pre">IndexError</span></tt> when the slice has a step, a negative
start value, or a stop value less than or equal to the start
value.</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>index</cite>: An integer or slice index to be applied to this cursor</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pymongo.cursor.Cursor.add_option">
<tt class="descname">add_option</tt><big>(</big><em>mask</em><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor.add_option" title="Permalink to this definition">¶</a></dt>
<dd><p>Set arbitary query flags using a bitmask.</p>
<p>To set the tailable flag:
cursor.add_option(2)</p>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.cursor.Cursor.alive">
<tt class="descname">alive</tt><a class="headerlink" href="#pymongo.cursor.Cursor.alive" title="Permalink to this definition">¶</a></dt>
<dd><p>Does this cursor have the potential to return more data?</p>
<p>This is mostly useful with <a class="reference external" href="http://www.mongodb.org/display/DOCS/Tailable+Cursors">tailable cursors</a>
since they will stop iterating even though they <em>may</em> return more
results in the future.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.5.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.cursor.Cursor.batch_size">
<tt class="descname">batch_size</tt><big>(</big><em>batch_size</em><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor.batch_size" title="Permalink to this definition">¶</a></dt>
<dd><p>Limits the number of documents returned in one batch. Each batch
requires a round trip to the server. It can be adjusted to optimize
performance and limit data transfer.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">batch_size can not override MongoDB’s internal limits on the
amount of data it will return to the client in a single batch (i.e
if you set batch size to 1,000,000,000, MongoDB will currently only
return 4-16MB of results per batch).</p>
</div>
<p>Raises <tt class="xref py py-class docutils literal"><span class="pre">TypeError</span></tt> if <cite>batch_size</cite> is not an instance
of <tt class="xref py py-class docutils literal"><span class="pre">int</span></tt>. Raises <tt class="xref py py-class docutils literal"><span class="pre">ValueError</span></tt> if <cite>batch_size</cite> is
less than <tt class="docutils literal"><span class="pre">0</span></tt>. Raises
<a class="reference internal" href="errors.html#pymongo.errors.InvalidOperation" title="pymongo.errors.InvalidOperation"><tt class="xref py py-class docutils literal"><span class="pre">InvalidOperation</span></tt></a> if this
<a class="reference internal" href="#pymongo.cursor.Cursor" title="pymongo.cursor.Cursor"><tt class="xref py py-class docutils literal"><span class="pre">Cursor</span></tt></a> has already been used. The last <cite>batch_size</cite>
applied to this cursor takes precedence.</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>batch_size</cite>: The size of each batch of results requested.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.9.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.cursor.Cursor.clone">
<tt class="descname">clone</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor.clone" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a clone of this cursor.</p>
<p>Returns a new Cursor instance with options matching those that have
been set on the current instance. The clone will be completely
unevaluated, even if the current instance has been partially or
completely evaluated.</p>
</dd></dl>
<dl class="method">
<dt id="pymongo.cursor.Cursor.close">
<tt class="descname">close</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor.close" title="Permalink to this definition">¶</a></dt>
<dd><p>Explicitly close / kill this cursor. Required for PyPy, Jython and
other Python implementations that don’t use reference counting
garbage collection.</p>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.cursor.Cursor.collection">
<tt class="descname">collection</tt><a class="headerlink" href="#pymongo.cursor.Cursor.collection" title="Permalink to this definition">¶</a></dt>
<dd><p>The <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> that this
<a class="reference internal" href="#pymongo.cursor.Cursor" title="pymongo.cursor.Cursor"><tt class="xref py py-class docutils literal"><span class="pre">Cursor</span></tt></a> is iterating.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.1.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.cursor.Cursor.count">
<tt class="descname">count</tt><big>(</big><em>with_limit_and_skip=False</em><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor.count" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the size of the results set for this query.</p>
<p>Returns the number of documents in the results set for this query. Does
not take <a class="reference internal" href="#pymongo.cursor.Cursor.limit" title="pymongo.cursor.Cursor.limit"><tt class="xref py py-meth docutils literal"><span class="pre">limit()</span></tt></a> and <a class="reference internal" href="#pymongo.cursor.Cursor.skip" title="pymongo.cursor.Cursor.skip"><tt class="xref py py-meth docutils literal"><span class="pre">skip()</span></tt></a> into account by default - set
<cite>with_limit_and_skip</cite> to <tt class="docutils literal"><span class="pre">True</span></tt> if that is the desired behavior.
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> on a database error.</p>
<p>With <a class="reference internal" href="mongo_replica_set_client.html#pymongo.mongo_replica_set_client.MongoReplicaSetClient" title="pymongo.mongo_replica_set_client.MongoReplicaSetClient"><tt class="xref py py-class docutils literal"><span class="pre">MongoReplicaSetClient</span></tt></a>
or <a class="reference internal" href="master_slave_connection.html#pymongo.master_slave_connection.MasterSlaveConnection" title="pymongo.master_slave_connection.MasterSlaveConnection"><tt class="xref py py-class docutils literal"><span class="pre">MasterSlaveConnection</span></tt></a>,
if <cite>read_preference</cite> is not
<tt class="xref py py-attr docutils literal"><span class="pre">pymongo.read_preferences.ReadPreference.PRIMARY</span></tt> or
<tt class="xref py py-attr docutils literal"><span class="pre">pymongo.read_preferences.ReadPreference.PRIMARY_PREFERRED</span></tt>, or
(deprecated) <cite>slave_okay</cite> is <cite>True</cite>, the count command will be sent to
a secondary or slave.</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>with_limit_and_skip</cite> (optional): take any <a class="reference internal" href="#pymongo.cursor.Cursor.limit" title="pymongo.cursor.Cursor.limit"><tt class="xref py py-meth docutils literal"><span class="pre">limit()</span></tt></a> or
<a class="reference internal" href="#pymongo.cursor.Cursor.skip" title="pymongo.cursor.Cursor.skip"><tt class="xref py py-meth docutils literal"><span class="pre">skip()</span></tt></a> that has been applied to this cursor into account when
getting the count</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The <cite>with_limit_and_skip</cite> parameter requires server
version <strong>>= 1.1.4-</strong></p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p><tt class="docutils literal"><span class="pre">count</span></tt> ignores <tt class="docutils literal"><span class="pre">network_timeout</span></tt>. For example, the
timeout is ignored in the following code:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="n">collection</span><span class="o">.</span><span class="n">find</span><span class="p">({},</span> <span class="n">network_timeout</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">count</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.1.1: </span>The <cite>with_limit_and_skip</cite> parameter.
<tt class="xref py py-meth docutils literal"><span class="pre">__len__()</span></tt> was deprecated in favor of
calling <a class="reference internal" href="#pymongo.cursor.Cursor.count" title="pymongo.cursor.Cursor.count"><tt class="xref py py-meth docutils literal"><span class="pre">count()</span></tt></a> with <cite>with_limit_and_skip</cite> set to <tt class="docutils literal"><span class="pre">True</span></tt>.</p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="pymongo.cursor.Cursor.cursor_id">
<tt class="descname">cursor_id</tt><a class="headerlink" href="#pymongo.cursor.Cursor.cursor_id" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the id of the cursor</p>
<p>Useful if you need to manage cursor ids and want to handle killing
cursors manually using
<a class="reference internal" href="mongo_client.html#pymongo.mongo_client.MongoClient.kill_cursors" title="pymongo.mongo_client.MongoClient.kill_cursors"><tt class="xref py py-meth docutils literal"><span class="pre">kill_cursors()</span></tt></a></p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.2.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.cursor.Cursor.distinct">
<tt class="descname">distinct</tt><big>(</big><em>key</em><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor.distinct" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a list of distinct values for <cite>key</cite> among all documents
in the result set of this query.</p>
<p>Raises <tt class="xref py py-class docutils literal"><span class="pre">TypeError</span></tt> if <cite>key</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>
<p>With <a class="reference internal" href="mongo_replica_set_client.html#pymongo.mongo_replica_set_client.MongoReplicaSetClient" title="pymongo.mongo_replica_set_client.MongoReplicaSetClient"><tt class="xref py py-class docutils literal"><span class="pre">MongoReplicaSetClient</span></tt></a>
or <a class="reference internal" href="master_slave_connection.html#pymongo.master_slave_connection.MasterSlaveConnection" title="pymongo.master_slave_connection.MasterSlaveConnection"><tt class="xref py py-class docutils literal"><span class="pre">MasterSlaveConnection</span></tt></a>,
if <cite>read_preference</cite> is
not <tt class="xref py py-attr docutils literal"><span class="pre">pymongo.read_preferences.ReadPreference.PRIMARY</span></tt> or
(deprecated) <cite>slave_okay</cite> is <cite>True</cite> the distinct command will be sent
to a secondary or slave.</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>key</cite>: name of key for which we want to get the distinct values</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Requires server version <strong>>= 1.1.3+</strong></p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="collection.html#pymongo.collection.Collection.distinct" title="pymongo.collection.Collection.distinct"><tt class="xref py py-meth docutils literal"><span class="pre">pymongo.collection.Collection.distinct()</span></tt></a></p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.2.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.cursor.Cursor.explain">
<tt class="descname">explain</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor.explain" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns an explain plan record for this cursor.</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/explain" name="pymongo.cursor.Cursor.explain"><em>explain</em></a></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.cursor.Cursor.hint">
<tt class="descname">hint</tt><big>(</big><em>index</em><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor.hint" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds a ‘hint’, telling Mongo the proper index to use for the query.</p>
<p>Judicious use of hints can greatly improve query
performance. When doing a query on multiple fields (at least
one of which is indexed) pass the indexed field as a hint to
the query. Hinting will not do anything if the corresponding
index does not exist. Raises
<a class="reference internal" href="errors.html#pymongo.errors.InvalidOperation" title="pymongo.errors.InvalidOperation"><tt class="xref py py-class docutils literal"><span class="pre">InvalidOperation</span></tt></a> if this cursor has
already been used.</p>
<p><cite>index</cite> should be an index as passed to
<a class="reference internal" href="collection.html#pymongo.collection.Collection.create_index" title="pymongo.collection.Collection.create_index"><tt class="xref py py-meth docutils literal"><span class="pre">create_index()</span></tt></a>
(e.g. <tt class="docutils literal"><span class="pre">[('field',</span> <span class="pre">ASCENDING)]</span></tt>). If <cite>index</cite>
is <tt class="docutils literal"><span class="pre">None</span></tt> any existing hints for this query are cleared. The
last hint applied to this cursor takes precedence over all
others.</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>index</cite>: index to hint on (as an index specifier)</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pymongo.cursor.Cursor.limit">
<tt class="descname">limit</tt><big>(</big><em>limit</em><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor.limit" title="Permalink to this definition">¶</a></dt>
<dd><p>Limits the number of results to be returned by this cursor.</p>
<p>Raises TypeError if limit is not an instance of int. Raises
InvalidOperation if this cursor has already been used. The
last <cite>limit</cite> applied to this cursor takes precedence. A limit
of <tt class="docutils literal"><span class="pre">0</span></tt> is equivalent to no limit.</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>limit</cite>: the number of results to return</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/limit" name="pymongo.cursor.Cursor.limit"><em>limit</em></a></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.cursor.Cursor.max_scan">
<tt class="descname">max_scan</tt><big>(</big><em>max_scan</em><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor.max_scan" title="Permalink to this definition">¶</a></dt>
<dd><p>Limit the number of documents to scan when performing the query.</p>
<p>Raises <a class="reference internal" href="errors.html#pymongo.errors.InvalidOperation" title="pymongo.errors.InvalidOperation"><tt class="xref py py-class docutils literal"><span class="pre">InvalidOperation</span></tt></a> if this
cursor has already been used. Only the last <a class="reference internal" href="#pymongo.cursor.Cursor.max_scan" title="pymongo.cursor.Cursor.max_scan"><tt class="xref py py-meth docutils literal"><span class="pre">max_scan()</span></tt></a>
applied to this cursor has any effect.</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>max_scan</cite>: the maximum number of documents to scan</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Requires server version <strong>>= 1.5.1</strong></p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.7.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pymongo.cursor.Cursor.remove_option">
<tt class="descname">remove_option</tt><big>(</big><em>mask</em><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor.remove_option" title="Permalink to this definition">¶</a></dt>
<dd><p>Unset arbitrary query flags using a bitmask.</p>
<p>To unset the tailable flag:
cursor.remove_option(2)</p>
</dd></dl>
<dl class="method">
<dt id="pymongo.cursor.Cursor.rewind">
<tt class="descname">rewind</tt><big>(</big><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor.rewind" title="Permalink to this definition">¶</a></dt>
<dd><p>Rewind this cursor to its unevaluated state.</p>
<p>Reset this cursor if it has been partially or completely evaluated.
Any options that are present on the cursor will remain in effect.
Future iterating performed on this cursor will cause new queries to
be sent to the server, even if the resultant data has already been
retrieved by this cursor.</p>
</dd></dl>
<dl class="method">
<dt id="pymongo.cursor.Cursor.skip">
<tt class="descname">skip</tt><big>(</big><em>skip</em><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor.skip" title="Permalink to this definition">¶</a></dt>
<dd><p>Skips the first <cite>skip</cite> results of this cursor.</p>
<p>Raises TypeError if skip is not an instance of int. Raises
InvalidOperation if this cursor has already been used. The last <cite>skip</cite>
applied to this cursor takes precedence.</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>skip</cite>: the number of results to skip</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pymongo.cursor.Cursor.sort">
<tt class="descname">sort</tt><big>(</big><em>key_or_list</em>, <em>direction=None</em><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor.sort" title="Permalink to this definition">¶</a></dt>
<dd><p>Sorts this cursor’s results.</p>
<p>Takes either a single key and a direction, or a list of (key,
direction) pairs. The key(s) must be an instance of <tt class="docutils literal"><span class="pre">(str,</span>
<span class="pre">unicode)</span></tt>, and the direction(s) must be one of
(<a class="reference internal" href="collection.html#pymongo.ASCENDING" title="pymongo.ASCENDING"><tt class="xref py py-data docutils literal"><span class="pre">ASCENDING</span></tt></a>,
<a class="reference internal" href="collection.html#pymongo.DESCENDING" title="pymongo.DESCENDING"><tt class="xref py py-data docutils literal"><span class="pre">DESCENDING</span></tt></a>). Raises
<a class="reference internal" href="errors.html#pymongo.errors.InvalidOperation" title="pymongo.errors.InvalidOperation"><tt class="xref py py-class docutils literal"><span class="pre">InvalidOperation</span></tt></a> if this cursor has
already been used. Only the last <a class="reference internal" href="#pymongo.cursor.Cursor.sort" title="pymongo.cursor.Cursor.sort"><tt class="xref py py-meth docutils literal"><span class="pre">sort()</span></tt></a> applied to this
cursor has any effect.</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>key_or_list</cite>: a single key or a list of (key, direction)
pairs specifying the keys to sort on</li>
<li><cite>direction</cite> (optional): only used if <cite>key_or_list</cite> is a single
key, if not given <a class="reference internal" href="collection.html#pymongo.ASCENDING" title="pymongo.ASCENDING"><tt class="xref py py-data docutils literal"><span class="pre">ASCENDING</span></tt></a> is assumed</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pymongo.cursor.Cursor.where">
<tt class="descname">where</tt><big>(</big><em>code</em><big>)</big><a class="headerlink" href="#pymongo.cursor.Cursor.where" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds a $where clause to this query.</p>
<p>The <cite>code</cite> argument must be 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 <a class="reference internal" href="../bson/code.html#bson.code.Code" title="bson.code.Code"><tt class="xref py py-class docutils literal"><span class="pre">Code</span></tt></a>
containing a JavaScript expression. This expression will be
evaluated for each document scanned. Only those documents
for which the expression evaluates to <em>true</em> will be returned
as results. The keyword <em>this</em> refers to the object currently
being scanned.</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). Raises
<a class="reference internal" href="errors.html#pymongo.errors.InvalidOperation" title="pymongo.errors.InvalidOperation"><tt class="xref py py-class docutils literal"><span class="pre">InvalidOperation</span></tt></a> if this
<a class="reference internal" href="#pymongo.cursor.Cursor" title="pymongo.cursor.Cursor"><tt class="xref py py-class docutils literal"><span class="pre">Cursor</span></tt></a> has already been used. Only the last call to
<a class="reference internal" href="#pymongo.cursor.Cursor.where" title="pymongo.cursor.Cursor.where"><tt class="xref py py-meth docutils literal"><span class="pre">where()</span></tt></a> applied to a <a class="reference internal" href="#pymongo.cursor.Cursor" title="pymongo.cursor.Cursor"><tt class="xref py py-class docutils literal"><span class="pre">Cursor</span></tt></a> has any effect.</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>: JavaScript expression to use as a filter</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h4>Previous topic</h4>
<p class="topless"><a href="collection.html"
title="previous chapter"><tt class="docutils literal"><span class="pre">collection</span></tt> – Collection level operations</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="errors.html"
title="next chapter"><tt class="docutils literal"><span class="pre">errors</span></tt> – Exceptions raised by the <tt class="docutils literal"><span class="pre">pymongo</span></tt> package</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../../_sources/api/pymongo/cursor.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="errors.html" title="errors – Exceptions raised by the pymongo package"
>next</a> |</li>
<li class="right" >
<a href="collection.html" title="collection – Collection level operations"
>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>
|