<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Niraj Patkar on Medium]]></title>
        <description><![CDATA[Stories by Niraj Patkar on Medium]]></description>
        <link>https://medium.com/@niraj_patkar?source=rss-6328dfc4b456------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qNueqyJhULtk58xFaTfiHQ.png</url>
            <title>Stories by Niraj Patkar on Medium</title>
            <link>https://medium.com/@niraj_patkar?source=rss-6328dfc4b456------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 14:17:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@niraj_patkar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Getting Started with Change Streams in MongoDB]]></title>
            <link>https://blog.nonstopio.com/getting-started-with-change-streams-in-mongodb-924126c03a7b?source=rss-6328dfc4b456------2</link>
            <guid isPermaLink="false">https://medium.com/p/924126c03a7b</guid>
            <category><![CDATA[nosql]]></category>
            <category><![CDATA[change-streams]]></category>
            <category><![CDATA[mongodb]]></category>
            <dc:creator><![CDATA[Niraj Patkar]]></dc:creator>
            <pubDate>Thu, 18 Aug 2022 18:00:46 GMT</pubDate>
            <atom:updated>2022-08-18T18:01:04.379Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZvjqQSOJVig5zfm1.png" /></figure><p><strong>MongoDB 6.0</strong> has been generally available for a month now.</p><p>If we look at What’s New, we see some usual stuff… new operators like $sortArray, or enhancements to existing operators like $lookup, or enhancements to time series collections like support for secondary and compound indexes.</p><p>But, what excites me most is MongoDB team’s continued focus on <strong>Change Streams</strong>. With 6.0, Change Streams have become more potent. Applications can now receive before and after states (pre &amp; post images) of the changed document . And Change Stream events now include data definition language operations. Both these additions potentially open up interesting new possibilities for event-driven architecture.</p><p>But <strong>Change Streams</strong> are not new to MongoDB. They were first introduced in MongoDB 3.6 &amp; gradually enhanced from there. Let’s look at basics of Change Streams in MongoDB.</p><p><strong>What are Change Streams?</strong></p><p>Change Streams is basically a way for applications to watch for or listen to data changes in MongoDB.</p><p><strong>What changes can we watch for?</strong></p><p>With Change Streams, an application can watch for changes on a single collection, or an entire database, or even an entire deployment.</p><p>Prior to 6.0, applications could watch only for the data changes. But, with 6.0, changes to data definition like creating or dropping of an index can also be watched.</p><p>What makes Change Streams powerful is their ability to piggyback on the aggregation framework. This allows applications to look out for very specific changes, which creates limitless possibilities for employing Change Streams.</p><p><strong>How to use Change Streams?</strong></p><p>While Change Streams can sound complex as a concept, using them is not so. An application can open a Change Stream on a collection as below:</p><pre>const devices = db.collection(&#39;devices&#39;);<br>const deviceChangeIterator = devices.watch();<br>const next = await deviceChangeIterator.next();</pre><p>We can easily tweak the change stream to match our needs using aggregation pipeline. e.g. To watch changes to ‘router’ type of devices rather than all:</p><pre>const filter = [ { $match: { ‘fullDocument.type’: ‘router’ } } ];<br>const devices = db.collection(&#39;devices&#39;);<br>const deviceChangeIterator = devices.watch(filter);<br>const next = await deviceChangeIterator.next();</pre><p><strong>Where to use Change Streams?</strong></p><p>The Change Streams offer an interesting new design paradigm to our applications. With Change Streams, applications can be designed to respond to change events (lazy architecture) rather than actively looking up the database &amp; figuring out an action plan (eager architecture).</p><p>This approach is not only resource optimal, but also simpler to implement. Event driven architecture allows applications to differentially relax.</p><p>Change Streams could be used effectively in numerous use cases. They are a natural fit for all sorts of monitoring applications. Ditto for event tracker applications &amp; applications with well defined rule based action plans.</p><p>Newly added ability to include data definition operations in Change Streams might even encourage users to create applications aiding database &amp; application availability &amp; restoration.</p><p><strong>Comments?</strong></p><p>What are your thoughts on Change Streams? Feel free to share here. And do reach out if you need any assistance with Change Streams in particular or with MongoDB in general.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=924126c03a7b" width="1" height="1" alt=""><hr><p><a href="https://blog.nonstopio.com/getting-started-with-change-streams-in-mongodb-924126c03a7b">Getting Started with Change Streams in MongoDB</a> was originally published in <a href="https://blog.nonstopio.com/">nonstopio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>