Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-release > by-pkgid > bc55833f04f370ac3ed453ef5b0ad686 > files > 246

python2-gridfs-3.7.2-1.mga7.i586.rpm


<!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="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>cursor – Tools for iterating over MongoDB query results &#8212; PyMongo 3.7.2 documentation</title>
    <link rel="stylesheet" href="../../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></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/language_data.js"></script>
    
    <script type="text/javascript" src="../../_static/sidebar.js"></script>
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="cursor_manager – Managers to handle when cursors are killed after being closed" href="cursor_manager.html" />
    <link rel="prev" title="command_cursor – Tools for iterating over MongoDB command results" href="command_cursor.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <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="cursor_manager.html" title="cursor_manager – Managers to handle when cursors are killed after being closed"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="command_cursor.html" title="command_cursor – Tools for iterating over MongoDB command results"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">PyMongo 3.7.2 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >API Documentation</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U"><code class="docutils literal notranslate"><span class="pre">pymongo</span></code> – Python driver for MongoDB</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-pymongo.cursor">
<span id="cursor-tools-for-iterating-over-mongodb-query-results"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">cursor</span></code> – 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.CursorType">
<em class="property">class </em><code class="descclassname">pymongo.cursor.</code><code class="descname">CursorType</code><a class="headerlink" href="#pymongo.cursor.CursorType" title="Permalink to this definition">¶</a></dt>
<dd><dl class="attribute">
<dt id="pymongo.cursor.CursorType.NON_TAILABLE">
<code class="descname">NON_TAILABLE</code><a class="headerlink" href="#pymongo.cursor.CursorType.NON_TAILABLE" title="Permalink to this definition">¶</a></dt>
<dd><p>The standard cursor type.</p>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.cursor.CursorType.TAILABLE">
<code class="descname">TAILABLE</code><a class="headerlink" href="#pymongo.cursor.CursorType.TAILABLE" title="Permalink to this definition">¶</a></dt>
<dd><p>The tailable cursor type.</p>
<p>Tailable cursors are only for use with capped collections. They are not
closed when the last data is retrieved but are kept open and the cursor
location marks the final document position. If more data is received
iteration of the cursor will continue from the last document received.</p>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.cursor.CursorType.TAILABLE_AWAIT">
<code class="descname">TAILABLE_AWAIT</code><a class="headerlink" href="#pymongo.cursor.CursorType.TAILABLE_AWAIT" title="Permalink to this definition">¶</a></dt>
<dd><p>A tailable cursor with the await option set.</p>
<p>Creates a tailable cursor that will wait for a few seconds after returning
the full result set so that it can capture and return additional data added
during the query.</p>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.cursor.CursorType.EXHAUST">
<code class="descname">EXHAUST</code><a class="headerlink" href="#pymongo.cursor.CursorType.EXHAUST" title="Permalink to this definition">¶</a></dt>
<dd><p>An exhaust cursor.</p>
<p>MongoDB will stream batched results to the client without waiting for the
client to request each batch, reducing latency.</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="pymongo.cursor.Cursor">
<em class="property">class </em><code class="descclassname">pymongo.cursor.</code><code class="descname">Cursor</code><span class="sig-paren">(</span><em>collection</em>, <em>filter=None</em>, <em>projection=None</em>, <em>skip=0</em>, <em>limit=0</em>, <em>no_cursor_timeout=False</em>, <em>cursor_type=CursorType.NON_TAILABLE</em>, <em>sort=None</em>, <em>allow_partial_results=False</em>, <em>oplog_replay=False</em>, <em>modifiers=None</em>, <em>batch_size=0</em>, <em>manipulate=True</em>, <em>collation=None</em>, <em>hint=None</em>, <em>max_scan=None</em>, <em>max_time_ms=None</em>, <em>max=None</em>, <em>min=None</em>, <em>return_key=False</em>, <em>show_record_id=False</em>, <em>snapshot=False</em>, <em>comment=None</em><span class="sig-paren">)</span><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"><code class="xref py py-meth docutils literal notranslate"><span class="pre">find()</span></code></a> instead.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="admonition-title">The MongoDB documentation on</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>
<code class="descname">c[index]</code></dt>
<dd><p>See <a class="reference internal" href="#pymongo.cursor.Cursor.__getitem__" title="pymongo.cursor.Cursor.__getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getitem__()</span></code></a>.</p>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.__getitem__">
<code class="descname">__getitem__</code><span class="sig-paren">(</span><em>index</em><span class="sig-paren">)</span><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"><code class="xref py py-class docutils literal notranslate"><span class="pre">InvalidOperation</span></code></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-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </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 <code class="xref py py-class docutils literal notranslate"><span class="pre">IndexError</span></code> 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-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </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 <code class="docutils literal notranslate"><span class="pre">5</span></code> and skip of
<code class="docutils literal notranslate"><span class="pre">20</span></code> 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
<code class="xref py py-class docutils literal notranslate"><span class="pre">IndexError</span></code> 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">
<code class="descname">add_option</code><span class="sig-paren">(</span><em>mask</em><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.cursor.Cursor.add_option" title="Permalink to this definition">¶</a></dt>
<dd><p>Set arbitrary 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.address">
<code class="descname">address</code><a class="headerlink" href="#pymongo.cursor.Cursor.address" title="Permalink to this definition">¶</a></dt>
<dd><p>The (host, port) of the server used, or None.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.0: </span>Renamed from “conn_id”.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.cursor.Cursor.alive">
<code class="descname">alive</code><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>
<p>With regular cursors, simply use a for loop instead of <a class="reference internal" href="#pymongo.cursor.Cursor.alive" title="pymongo.cursor.Cursor.alive"><code class="xref py py-attr docutils literal notranslate"><span class="pre">alive</span></code></a>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">doc</span> <span class="ow">in</span> <span class="n">collection</span><span class="o">.</span><span class="n">find</span><span class="p">():</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">doc</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Even if <a class="reference internal" href="#pymongo.cursor.Cursor.alive" title="pymongo.cursor.Cursor.alive"><code class="xref py py-attr docutils literal notranslate"><span class="pre">alive</span></code></a> is True, <a class="reference internal" href="#pymongo.cursor.Cursor.next" title="pymongo.cursor.Cursor.next"><code class="xref py py-meth docutils literal notranslate"><span class="pre">next()</span></code></a> can raise
<code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code>. <a class="reference internal" href="#pymongo.cursor.Cursor.alive" title="pymongo.cursor.Cursor.alive"><code class="xref py py-attr docutils literal notranslate"><span class="pre">alive</span></code></a> can also be True while iterating
a cursor from a failed server. In this case <a class="reference internal" href="#pymongo.cursor.Cursor.alive" title="pymongo.cursor.Cursor.alive"><code class="xref py py-attr docutils literal notranslate"><span class="pre">alive</span></code></a> will
return False after <a class="reference internal" href="#pymongo.cursor.Cursor.next" title="pymongo.cursor.Cursor.next"><code class="xref py py-meth docutils literal notranslate"><span class="pre">next()</span></code></a> fails to retrieve the next batch
of results from the server.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.batch_size">
<code class="descname">batch_size</code><span class="sig-paren">(</span><em>batch_size</em><span class="sig-paren">)</span><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 <code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code> if <cite>batch_size</cite> is not an integer.
Raises <code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code> if <cite>batch_size</cite> is less than <code class="docutils literal notranslate"><span class="pre">0</span></code>.
Raises <a class="reference internal" href="errors.html#pymongo.errors.InvalidOperation" title="pymongo.errors.InvalidOperation"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidOperation</span></code></a> if this
<a class="reference internal" href="#pymongo.cursor.Cursor" title="pymongo.cursor.Cursor"><code class="xref py py-class docutils literal notranslate"><span class="pre">Cursor</span></code></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>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.clone">
<code class="descname">clone</code><span class="sig-paren">(</span><span class="sig-paren">)</span><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">
<code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.cursor.Cursor.close" title="Permalink to this definition">¶</a></dt>
<dd><p>Explicitly close / kill this cursor.</p>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.collation">
<code class="descname">collation</code><span class="sig-paren">(</span><em>collation</em><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.cursor.Cursor.collation" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds a <a class="reference internal" href="collation.html#pymongo.collation.Collation" title="pymongo.collation.Collation"><code class="xref py py-class docutils literal notranslate"><span class="pre">Collation</span></code></a> to this query.</p>
<p>This option is only supported on MongoDB 3.4 and above.</p>
<p>Raises <code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code> if <cite>collation</cite> is not an instance of
<a class="reference internal" href="collation.html#pymongo.collation.Collation" title="pymongo.collation.Collation"><code class="xref py py-class docutils literal notranslate"><span class="pre">Collation</span></code></a> or a <code class="docutils literal notranslate"><span class="pre">dict</span></code>. Raises
<a class="reference internal" href="errors.html#pymongo.errors.InvalidOperation" title="pymongo.errors.InvalidOperation"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidOperation</span></code></a> if this <a class="reference internal" href="#pymongo.cursor.Cursor" title="pymongo.cursor.Cursor"><code class="xref py py-class docutils literal notranslate"><span class="pre">Cursor</span></code></a> has
already been used. Only the last collation 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>collation</cite>: An instance of <a class="reference internal" href="collation.html#pymongo.collation.Collation" title="pymongo.collation.Collation"><code class="xref py py-class docutils literal notranslate"><span class="pre">Collation</span></code></a>.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.cursor.Cursor.collection">
<code class="descname">collection</code><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"><code class="xref py py-class docutils literal notranslate"><span class="pre">Collection</span></code></a> that this
<a class="reference internal" href="#pymongo.cursor.Cursor" title="pymongo.cursor.Cursor"><code class="xref py py-class docutils literal notranslate"><span class="pre">Cursor</span></code></a> is iterating.</p>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.comment">
<code class="descname">comment</code><span class="sig-paren">(</span><em>comment</em><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.cursor.Cursor.comment" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds a ‘comment’ to the cursor.</p>
<p><a class="reference external" href="http://docs.mongodb.org/manual/reference/operator/comment/">http://docs.mongodb.org/manual/reference/operator/comment/</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>comment</cite>: A string or document</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.7.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.count">
<code class="descname">count</code><span class="sig-paren">(</span><em>with_limit_and_skip=False</em><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.cursor.Cursor.count" title="Permalink to this definition">¶</a></dt>
<dd><p><strong>DEPRECATED</strong> - Get the size of the results set for this query.</p>
<p>The <a class="reference internal" href="#pymongo.cursor.Cursor.count" title="pymongo.cursor.Cursor.count"><code class="xref py py-meth docutils literal notranslate"><span class="pre">count()</span></code></a> method is deprecated and <strong>not</strong> supported in a
transaction. Please use
<a class="reference internal" href="collection.html#pymongo.collection.Collection.count_documents" title="pymongo.collection.Collection.count_documents"><code class="xref py py-meth docutils literal notranslate"><span class="pre">count_documents()</span></code></a> instead.</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"><code class="xref py py-meth docutils literal notranslate"><span class="pre">limit()</span></code></a> and <a class="reference internal" href="#pymongo.cursor.Cursor.skip" title="pymongo.cursor.Cursor.skip"><code class="xref py py-meth docutils literal notranslate"><span class="pre">skip()</span></code></a> into account by default - set
<cite>with_limit_and_skip</cite> to <code class="docutils literal notranslate"><span class="pre">True</span></code> if that is the desired behavior.
Raises <a class="reference internal" href="errors.html#pymongo.errors.OperationFailure" title="pymongo.errors.OperationFailure"><code class="xref py py-class docutils literal notranslate"><span class="pre">OperationFailure</span></code></a> on a database error.</p>
<p>When used with MongoDB &gt;= 2.6, <a class="reference internal" href="#pymongo.cursor.Cursor.count" title="pymongo.cursor.Cursor.count"><code class="xref py py-meth docutils literal notranslate"><span class="pre">count()</span></code></a> uses any <a class="reference internal" href="#pymongo.cursor.Cursor.hint" title="pymongo.cursor.Cursor.hint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">hint()</span></code></a>
applied to the query. In the following example the hint is passed to
the count command:</p>
<blockquote>
<div>collection.find({‘field’: ‘value’}).hint(‘field_1’).count()</div></blockquote>
<p>The <a class="reference internal" href="#pymongo.cursor.Cursor.count" title="pymongo.cursor.Cursor.count"><code class="xref py py-meth docutils literal notranslate"><span class="pre">count()</span></code></a> method obeys the
<a class="reference internal" href="collection.html#pymongo.collection.Collection.read_preference" title="pymongo.collection.Collection.read_preference"><code class="xref py py-attr docutils literal notranslate"><span class="pre">read_preference</span></code></a> of the
<a class="reference internal" href="collection.html#pymongo.collection.Collection" title="pymongo.collection.Collection"><code class="xref py py-class docutils literal notranslate"><span class="pre">Collection</span></code></a> instance on which
<a class="reference internal" href="collection.html#pymongo.collection.Collection.find" title="pymongo.collection.Collection.find"><code class="xref py py-meth docutils literal notranslate"><span class="pre">find()</span></code></a> was called.</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"><code class="xref py py-meth docutils literal notranslate"><span class="pre">limit()</span></code></a> or
<a class="reference internal" href="#pymongo.cursor.Cursor.skip" title="pymongo.cursor.Cursor.skip"><code class="xref py py-meth docutils literal notranslate"><span class="pre">skip()</span></code></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>&gt;= 1.1.4-</strong></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.7: </span>Deprecated.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.8: </span>The <a class="reference internal" href="#pymongo.cursor.Cursor.count" title="pymongo.cursor.Cursor.count"><code class="xref py py-meth docutils literal notranslate"><span class="pre">count()</span></code></a> method now supports <a class="reference internal" href="#pymongo.cursor.Cursor.hint" title="pymongo.cursor.Cursor.hint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">hint()</span></code></a>.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="pymongo.cursor.Cursor.cursor_id">
<code class="descname">cursor_id</code><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"><code class="xref py py-meth docutils literal notranslate"><span class="pre">kill_cursors()</span></code></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">
<code class="descname">distinct</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><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 <code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code> if <cite>key</cite> is not an instance of
<code class="xref py py-class docutils literal notranslate"><span class="pre">basestring</span></code> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code> in python 3).</p>
<p>The <a class="reference internal" href="#pymongo.cursor.Cursor.distinct" title="pymongo.cursor.Cursor.distinct"><code class="xref py py-meth docutils literal notranslate"><span class="pre">distinct()</span></code></a> method obeys the
<a class="reference internal" href="collection.html#pymongo.collection.Collection.read_preference" title="pymongo.collection.Collection.read_preference"><code class="xref py py-attr docutils literal notranslate"><span class="pre">read_preference</span></code></a> of the
<a class="reference internal" href="collection.html#pymongo.collection.Collection" title="pymongo.collection.Collection"><code class="xref py py-class docutils literal notranslate"><span class="pre">Collection</span></code></a> instance on which
<a class="reference internal" href="collection.html#pymongo.collection.Collection.find" title="pymongo.collection.Collection.find"><code class="xref py py-meth docutils literal notranslate"><span class="pre">find()</span></code></a> was called.</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 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"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pymongo.collection.Collection.distinct()</span></code></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.explain">
<code class="descname">explain</code><span class="sig-paren">(</span><span class="sig-paren">)</span><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 seealso">
<p class="first admonition-title">See also</p>
<p class="admonition-title">The MongoDB documentation on</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">
<code class="descname">hint</code><span class="sig-paren">(</span><em>index</em><span class="sig-paren">)</span><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"><code class="xref py py-class docutils literal notranslate"><span class="pre">InvalidOperation</span></code></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"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_index()</span></code></a>
(e.g. <code class="docutils literal notranslate"><span class="pre">[('field',</span> <span class="pre">ASCENDING)]</span></code>) or the name of the index.
If <cite>index</cite> is <code class="docutils literal notranslate"><span class="pre">None</span></code> any existing hint for this query is
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>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.8: </span>The <a class="reference internal" href="#pymongo.cursor.Cursor.hint" title="pymongo.cursor.Cursor.hint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">hint()</span></code></a> method accepts the name of the index.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.limit">
<code class="descname">limit</code><span class="sig-paren">(</span><em>limit</em><span class="sig-paren">)</span><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 <code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code> if <cite>limit</cite> is not an integer. Raises
<a class="reference internal" href="errors.html#pymongo.errors.InvalidOperation" title="pymongo.errors.InvalidOperation"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidOperation</span></code></a> if this <a class="reference internal" href="#pymongo.cursor.Cursor" title="pymongo.cursor.Cursor"><code class="xref py py-class docutils literal notranslate"><span class="pre">Cursor</span></code></a>
has already been used. The last <cite>limit</cite> applied to this cursor
takes precedence. A limit of <code class="docutils literal notranslate"><span class="pre">0</span></code> 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 seealso">
<p class="first admonition-title">See also</p>
<p class="admonition-title">The MongoDB documentation on</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">
<code class="descname">max</code><span class="sig-paren">(</span><em>spec</em><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.cursor.Cursor.max" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds <cite>max</cite> operator that specifies upper bound for specific index.</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>spec</cite>: a list of field, limit pairs specifying the exclusive
upper bound for all keys of a specific index in order.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.7.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.max_await_time_ms">
<code class="descname">max_await_time_ms</code><span class="sig-paren">(</span><em>max_await_time_ms</em><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.cursor.Cursor.max_await_time_ms" title="Permalink to this definition">¶</a></dt>
<dd><p>Specifies a time limit for a getMore operation on a
<a class="reference internal" href="#pymongo.cursor.CursorType.TAILABLE_AWAIT" title="pymongo.cursor.CursorType.TAILABLE_AWAIT"><code class="xref py py-attr docutils literal notranslate"><span class="pre">TAILABLE_AWAIT</span></code></a> cursor. For all other
types of cursor max_await_time_ms is ignored.</p>
<p>Raises <code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code> if <cite>max_await_time_ms</cite> is not an integer or
<code class="docutils literal notranslate"><span class="pre">None</span></code>. Raises <a class="reference internal" href="errors.html#pymongo.errors.InvalidOperation" title="pymongo.errors.InvalidOperation"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidOperation</span></code></a> if this
<a class="reference internal" href="#pymongo.cursor.Cursor" title="pymongo.cursor.Cursor"><code class="xref py py-class docutils literal notranslate"><span class="pre">Cursor</span></code></a> has already been used.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><cite>max_await_time_ms</cite> requires server version <strong>&gt;= 3.2</strong></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>max_await_time_ms</cite>: the time limit after which the operation is
aborted</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.2.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.max_scan">
<code class="descname">max_scan</code><span class="sig-paren">(</span><em>max_scan</em><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.cursor.Cursor.max_scan" title="Permalink to this definition">¶</a></dt>
<dd><p><strong>DEPRECATED</strong> - 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"><code class="xref py py-class docutils literal notranslate"><span class="pre">InvalidOperation</span></code></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"><code class="xref py py-meth docutils literal notranslate"><span class="pre">max_scan()</span></code></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="versionchanged">
<p><span class="versionmodified">Changed in version 3.7: </span>Deprecated <a class="reference internal" href="#pymongo.cursor.Cursor.max_scan" title="pymongo.cursor.Cursor.max_scan"><code class="xref py py-meth docutils literal notranslate"><span class="pre">max_scan()</span></code></a>. Support for this option is deprecated in
MongoDB 4.0. Use <a class="reference internal" href="#pymongo.cursor.Cursor.max_time_ms" title="pymongo.cursor.Cursor.max_time_ms"><code class="xref py py-meth docutils literal notranslate"><span class="pre">max_time_ms()</span></code></a> instead to limit server side
execution time.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.max_time_ms">
<code class="descname">max_time_ms</code><span class="sig-paren">(</span><em>max_time_ms</em><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.cursor.Cursor.max_time_ms" title="Permalink to this definition">¶</a></dt>
<dd><p>Specifies a time limit for a query operation. If the specified
time is exceeded, the operation will be aborted and
<a class="reference internal" href="errors.html#pymongo.errors.ExecutionTimeout" title="pymongo.errors.ExecutionTimeout"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ExecutionTimeout</span></code></a> is raised. If <cite>max_time_ms</cite>
is <code class="docutils literal notranslate"><span class="pre">None</span></code> no limit is applied.</p>
<p>Raises <code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code> if <cite>max_time_ms</cite> is not an integer or <code class="docutils literal notranslate"><span class="pre">None</span></code>.
Raises <a class="reference internal" href="errors.html#pymongo.errors.InvalidOperation" title="pymongo.errors.InvalidOperation"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidOperation</span></code></a> if this <a class="reference internal" href="#pymongo.cursor.Cursor" title="pymongo.cursor.Cursor"><code class="xref py py-class docutils literal notranslate"><span class="pre">Cursor</span></code></a>
has already been used.</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_time_ms</cite>: the time limit after which the operation is aborted</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.min">
<code class="descname">min</code><span class="sig-paren">(</span><em>spec</em><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.cursor.Cursor.min" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds <cite>min</cite> operator that specifies lower bound for specific index.</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>spec</cite>: a list of field, limit pairs specifying the inclusive
lower bound for all keys of a specific index in order.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.7.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.next">
<code class="descname">next</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.cursor.Cursor.next" title="Permalink to this definition">¶</a></dt>
<dd><p>Advance the cursor.</p>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.remove_option">
<code class="descname">remove_option</code><span class="sig-paren">(</span><em>mask</em><span class="sig-paren">)</span><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="attribute">
<dt id="pymongo.cursor.Cursor.retrieved">
<code class="descname">retrieved</code><a class="headerlink" href="#pymongo.cursor.Cursor.retrieved" title="Permalink to this definition">¶</a></dt>
<dd><p>The number of documents retrieved so far.</p>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.rewind">
<code class="descname">rewind</code><span class="sig-paren">(</span><span class="sig-paren">)</span><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="attribute">
<dt id="pymongo.cursor.Cursor.session">
<code class="descname">session</code><a class="headerlink" href="#pymongo.cursor.Cursor.session" title="Permalink to this definition">¶</a></dt>
<dd><p>The cursor’s <a class="reference internal" href="client_session.html#pymongo.client_session.ClientSession" title="pymongo.client_session.ClientSession"><code class="xref py py-class docutils literal notranslate"><span class="pre">ClientSession</span></code></a>, or None.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.6.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.skip">
<code class="descname">skip</code><span class="sig-paren">(</span><em>skip</em><span class="sig-paren">)</span><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 <code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code> if <cite>skip</cite> is not an integer. Raises
<code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code> if <cite>skip</cite> is less than <code class="docutils literal notranslate"><span class="pre">0</span></code>. Raises
<a class="reference internal" href="errors.html#pymongo.errors.InvalidOperation" title="pymongo.errors.InvalidOperation"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidOperation</span></code></a> if this <a class="reference internal" href="#pymongo.cursor.Cursor" title="pymongo.cursor.Cursor"><code class="xref py py-class docutils literal notranslate"><span class="pre">Cursor</span></code></a> 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">
<code class="descname">sort</code><span class="sig-paren">(</span><em>key_or_list</em>, <em>direction=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.cursor.Cursor.sort" title="Permalink to this definition">¶</a></dt>
<dd><p>Sorts this cursor’s results.</p>
<p>Pass a field name and a direction, either
<a class="reference internal" href="collection.html#pymongo.ASCENDING" title="pymongo.ASCENDING"><code class="xref py py-data docutils literal notranslate"><span class="pre">ASCENDING</span></code></a> or <a class="reference internal" href="collection.html#pymongo.DESCENDING" title="pymongo.DESCENDING"><code class="xref py py-data docutils literal notranslate"><span class="pre">DESCENDING</span></code></a>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">doc</span> <span class="ow">in</span> <span class="n">collection</span><span class="o">.</span><span class="n">find</span><span class="p">()</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="s1">&#39;field&#39;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">):</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">doc</span><span class="p">)</span>
</pre></div>
</div>
<p>To sort by multiple fields, pass a list of (key, direction) pairs:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">doc</span> <span class="ow">in</span> <span class="n">collection</span><span class="o">.</span><span class="n">find</span><span class="p">()</span><span class="o">.</span><span class="n">sort</span><span class="p">([</span>
        <span class="p">(</span><span class="s1">&#39;field1&#39;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">),</span>
        <span class="p">(</span><span class="s1">&#39;field2&#39;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">DESCENDING</span><span class="p">)]):</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">doc</span><span class="p">)</span>
</pre></div>
</div>
<p>Beginning with MongoDB version 2.6, text search results can be
sorted by relevance:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">cursor</span> <span class="o">=</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="p">{</span><span class="s1">&#39;$text&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;$search&#39;</span><span class="p">:</span> <span class="s1">&#39;some words&#39;</span><span class="p">}},</span>
    <span class="p">{</span><span class="s1">&#39;score&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;$meta&#39;</span><span class="p">:</span> <span class="s1">&#39;textScore&#39;</span><span class="p">}})</span>

<span class="c1"># Sort by &#39;score&#39; field.</span>
<span class="n">cursor</span><span class="o">.</span><span class="n">sort</span><span class="p">([(</span><span class="s1">&#39;score&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s1">&#39;$meta&#39;</span><span class="p">:</span> <span class="s1">&#39;textScore&#39;</span><span class="p">})])</span>

<span class="k">for</span> <span class="n">doc</span> <span class="ow">in</span> <span class="n">cursor</span><span class="p">:</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">doc</span><span class="p">)</span>
</pre></div>
</div>
<p>Raises <a class="reference internal" href="errors.html#pymongo.errors.InvalidOperation" title="pymongo.errors.InvalidOperation"><code class="xref py py-class docutils literal notranslate"><span class="pre">InvalidOperation</span></code></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"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sort()</span></code></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"><code class="xref py py-data docutils literal notranslate"><span class="pre">ASCENDING</span></code></a> is assumed</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pymongo.cursor.Cursor.where">
<code class="descname">where</code><span class="sig-paren">(</span><em>code</em><span class="sig-paren">)</span><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 <code class="xref py py-class docutils literal notranslate"><span class="pre">basestring</span></code>
(<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code> in python 3) or <a class="reference internal" href="../bson/code.html#bson.code.Code" title="bson.code.Code"><code class="xref py py-class docutils literal notranslate"><span class="pre">Code</span></code></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 <code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code> if <cite>code</cite> is not an instance of
<code class="xref py py-class docutils literal notranslate"><span class="pre">basestring</span></code> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code> in python 3). Raises
<a class="reference internal" href="errors.html#pymongo.errors.InvalidOperation" title="pymongo.errors.InvalidOperation"><code class="xref py py-class docutils literal notranslate"><span class="pre">InvalidOperation</span></code></a> if this
<a class="reference internal" href="#pymongo.cursor.Cursor" title="pymongo.cursor.Cursor"><code class="xref py py-class docutils literal notranslate"><span class="pre">Cursor</span></code></a> has already been used. Only the last call to
<a class="reference internal" href="#pymongo.cursor.Cursor.where" title="pymongo.cursor.Cursor.where"><code class="xref py py-meth docutils literal notranslate"><span class="pre">where()</span></code></a> applied to a <a class="reference internal" href="#pymongo.cursor.Cursor" title="pymongo.cursor.Cursor"><code class="xref py py-class docutils literal notranslate"><span class="pre">Cursor</span></code></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>

<dl class="class">
<dt id="pymongo.cursor.RawBatchCursor">
<em class="property">class </em><code class="descclassname">pymongo.cursor.</code><code class="descname">RawBatchCursor</code><span class="sig-paren">(</span><em>collection</em>, <em>filter=None</em>, <em>projection=None</em>, <em>skip=0</em>, <em>limit=0</em>, <em>no_cursor_timeout=False</em>, <em>cursor_type=CursorType.NON_TAILABLE</em>, <em>sort=None</em>, <em>allow_partial_results=False</em>, <em>oplog_replay=False</em>, <em>modifiers=None</em>, <em>batch_size=0</em>, <em>collation=None</em>, <em>hint=None</em>, <em>max_scan=None</em>, <em>max_time_ms=None</em>, <em>max=None</em>, <em>min=None</em>, <em>return_key=False</em>, <em>show_record_id=False</em>, <em>snapshot=False</em>, <em>comment=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.cursor.RawBatchCursor" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new cursor / iterator over raw batches of BSON data.</p>
<p>Should not be called directly by application developers -
see <a class="reference internal" href="collection.html#pymongo.collection.Collection.find_raw_batches" title="pymongo.collection.Collection.find_raw_batches"><code class="xref py py-meth docutils literal notranslate"><span class="pre">find_raw_batches()</span></code></a>
instead.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="admonition-title">The MongoDB documentation on</p>
<p class="last"><a class="reference external" href="http://dochub.mongodb.org/core/cursors" name="pymongo.cursor.RawBatchCursor"><em>cursors</em></a></p>
</div>
</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="command_cursor.html"
                        title="previous chapter"><code class="docutils literal notranslate"><span class="pre">command_cursor</span></code> – Tools for iterating over MongoDB command results</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="cursor_manager.html"
                        title="next chapter"><code class="docutils literal notranslate"><span class="pre">cursor_manager</span></code> – Managers to handle when cursors are killed after being closed</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/api/pymongo/cursor.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <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>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <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="cursor_manager.html" title="cursor_manager – Managers to handle when cursors are killed after being closed"
             >next</a> |</li>
        <li class="right" >
          <a href="command_cursor.html" title="command_cursor – Tools for iterating over MongoDB command results"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">PyMongo 3.7.2 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >API Documentation</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" ><code class="docutils literal notranslate"><span class="pre">pymongo</span></code> – Python driver for MongoDB</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright MongoDB, Inc. 2008-present. MongoDB, Mongo, and the leaf logo are registered trademarks of MongoDB, Inc.
    </div>
  </body>
</html>