<!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>change_stream – Watch changes on a collection — 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="client_session – Logical sessions for sequential operations" href="client_session.html" /> <link rel="prev" title="bulk – The bulk write operations interface" href="bulk.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="client_session.html" title="client_session – Logical sessions for sequential operations" accesskey="N">next</a> |</li> <li class="right" > <a href="bulk.html" title="bulk – The bulk write operations interface" accesskey="P">previous</a> |</li> <li class="nav-item nav-item-0"><a href="../../index.html">PyMongo 3.7.2 documentation</a> »</li> <li class="nav-item nav-item-1"><a href="../index.html" >API Documentation</a> »</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> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="module-pymongo.change_stream"> <span id="change-stream-watch-changes-on-a-collection"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">change_stream</span></code> – Watch changes on a collection<a class="headerlink" href="#module-pymongo.change_stream" title="Permalink to this headline">¶</a></h1> <p>ChangeStream cursor to iterate over changes on a collection.</p> <dl class="class"> <dt id="pymongo.change_stream.ChangeStream"> <em class="property">class </em><code class="descclassname">pymongo.change_stream.</code><code class="descname">ChangeStream</code><span class="sig-paren">(</span><em>target</em>, <em>pipeline</em>, <em>full_document</em>, <em>resume_after</em>, <em>max_await_time_ms</em>, <em>batch_size</em>, <em>collation</em>, <em>start_at_operation_time</em>, <em>session</em><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.change_stream.ChangeStream" title="Permalink to this definition">¶</a></dt> <dd><p>The internal abstract base class for change stream cursors.</p> <p>Should not be called directly by application developers. Use :meth:pymongo.collection.Collection.watch, :meth:pymongo.database.Database.watch, or :meth:pymongo.mongo_client.MongoClient.watch instead.</p> <p>Defines the interface for change streams. Should be subclassed to implement the <cite>ChangeStream._create_cursor</cite> abstract method, and the <cite>ChangeStream._database`and ChangeStream._aggregation_target</cite> abstract properties.</p> <dl class="method"> <dt id="pymongo.change_stream.ChangeStream.close"> <code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.change_stream.ChangeStream.close" title="Permalink to this definition">¶</a></dt> <dd><p>Close this ChangeStream.</p> </dd></dl> <dl class="method"> <dt id="pymongo.change_stream.ChangeStream.next"> <code class="descname">next</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.change_stream.ChangeStream.next" title="Permalink to this definition">¶</a></dt> <dd><p>Advance the cursor.</p> <p>This method blocks until the next change document is returned or an unrecoverable error is raised.</p> <p>Raises <code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code> if this ChangeStream is closed.</p> </dd></dl> </dd></dl> <dl class="class"> <dt id="pymongo.change_stream.ClusterChangeStream"> <em class="property">class </em><code class="descclassname">pymongo.change_stream.</code><code class="descname">ClusterChangeStream</code><span class="sig-paren">(</span><em>target</em>, <em>pipeline</em>, <em>full_document</em>, <em>resume_after</em>, <em>max_await_time_ms</em>, <em>batch_size</em>, <em>collation</em>, <em>start_at_operation_time</em>, <em>session</em><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.change_stream.ClusterChangeStream" title="Permalink to this definition">¶</a></dt> <dd><p>Class for creating a change stream on all collections on a cluster.</p> <p>Should not be called directly by application developers. Use helper method <a class="reference internal" href="mongo_client.html#pymongo.mongo_client.MongoClient.watch" title="pymongo.mongo_client.MongoClient.watch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pymongo.mongo_client.MongoClient.watch()</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/changeStreams" name="pymongo.change_stream.ClusterChangeStream"><em>changeStreams</em></a></p> </div> </dd></dl> <dl class="class"> <dt id="pymongo.change_stream.CollectionChangeStream"> <em class="property">class </em><code class="descclassname">pymongo.change_stream.</code><code class="descname">CollectionChangeStream</code><span class="sig-paren">(</span><em>target</em>, <em>pipeline</em>, <em>full_document</em>, <em>resume_after</em>, <em>max_await_time_ms</em>, <em>batch_size</em>, <em>collation</em>, <em>start_at_operation_time</em>, <em>session</em><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.change_stream.CollectionChangeStream" title="Permalink to this definition">¶</a></dt> <dd><p>Class for creating a change stream on a collection.</p> <p>Should not be called directly by application developers. Use helper method <a class="reference internal" href="collection.html#pymongo.collection.Collection.watch" title="pymongo.collection.Collection.watch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pymongo.collection.Collection.watch()</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/changeStreams" name="pymongo.change_stream.CollectionChangeStream"><em>changeStreams</em></a></p> </div> </dd></dl> <dl class="class"> <dt id="pymongo.change_stream.DatabaseChangeStream"> <em class="property">class </em><code class="descclassname">pymongo.change_stream.</code><code class="descname">DatabaseChangeStream</code><span class="sig-paren">(</span><em>target</em>, <em>pipeline</em>, <em>full_document</em>, <em>resume_after</em>, <em>max_await_time_ms</em>, <em>batch_size</em>, <em>collation</em>, <em>start_at_operation_time</em>, <em>session</em><span class="sig-paren">)</span><a class="headerlink" href="#pymongo.change_stream.DatabaseChangeStream" title="Permalink to this definition">¶</a></dt> <dd><p>Class for creating a change stream on all collections in a database.</p> <p>Should not be called directly by application developers. Use helper method <a class="reference internal" href="database.html#pymongo.database.Database.watch" title="pymongo.database.Database.watch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pymongo.database.Database.watch()</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/changeStreams" name="pymongo.change_stream.DatabaseChangeStream"><em>changeStreams</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="bulk.html" title="previous chapter"><code class="docutils literal notranslate"><span class="pre">bulk</span></code> – The bulk write operations interface</a></p> <h4>Next topic</h4> <p class="topless"><a href="client_session.html" title="next chapter"><code class="docutils literal notranslate"><span class="pre">client_session</span></code> – Logical sessions for sequential operations</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../../_sources/api/pymongo/change_stream.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="client_session.html" title="client_session – Logical sessions for sequential operations" >next</a> |</li> <li class="right" > <a href="bulk.html" title="bulk – The bulk write operations interface" >previous</a> |</li> <li class="nav-item nav-item-0"><a href="../../index.html">PyMongo 3.7.2 documentation</a> »</li> <li class="nav-item nav-item-1"><a href="../index.html" >API Documentation</a> »</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> »</li> </ul> </div> <div class="footer" role="contentinfo"> © Copyright MongoDB, Inc. 2008-present. MongoDB, Mongo, and the leaf logo are registered trademarks of MongoDB, Inc. </div> </body> </html>