<?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 Giovanni on Medium]]></title>
        <description><![CDATA[Stories by Giovanni on Medium]]></description>
        <link>https://medium.com/@94giovanni?source=rss-b4fdaed159a1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*75aDBEepdwsegUVX</url>
            <title>Stories by Giovanni on Medium</title>
            <link>https://medium.com/@94giovanni?source=rss-b4fdaed159a1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 12:13:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@94giovanni/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[Best Practices for MongoDB Timeseries Collection]]></title>
            <link>https://medium.com/@94giovanni/best-practices-for-mongodb-timeseries-collection-3fa9d29405ab?source=rss-b4fdaed159a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fa9d29405ab</guid>
            <category><![CDATA[mongo]]></category>
            <category><![CDATA[mongodb-atlas]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[timeseries]]></category>
            <category><![CDATA[best-practices]]></category>
            <dc:creator><![CDATA[Giovanni]]></dc:creator>
            <pubDate>Mon, 14 Apr 2025 15:30:16 GMT</pubDate>
            <atom:updated>2025-04-14T15:30:16.758Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ueq-_s4Bwo6Dj8fQ2d991w.png" /></figure><p>Recently, I worked with MongoDB Timeseries Collections (version 8.0.6) for a complex data migration project as a Software Consultant Engineer. I faced a lot of issues during the 16 months of work and I want to share all the best practices I learned to obtain the best performances and avoid problems working with Timeseries Collection.</p><h4>Document Schema &amp; Metafields</h4><p>The document schema design is the most important step because it impacts on every other activity. The metafields collection configuration is crucial to optimize performances. The best practice is to include in the metafields all fields that will be used in the indexes. Remeber: you can remove a metafield in any moment but you cannot add a new one.</p><h4>Granularity</h4><p>In the Timeseries Collection configuration, the granularity param is very import to boost the performances. This configuration impacts on the bucket time span size. The granularity param cannot be changed one you set it during the collection configuration. The best practice is to choose the best granularity value based on the ingestion rate period of your data source. Look at the below table to check all the possible values. For example, if the ingection rate period is 5 minutes, it is better to set the granularity on “seconds”; else if the ingestion rate period in 1 hour, it is better to set the granulairy on “minutes”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*88AyX12ZbNhNDh7SbkhiWw.png" /><figcaption><a href="https://www.mongodb.com/docs/v5.0/core/timeseries/timeseries-granularity/#:~:text=Setting%20the%20granularity%20parameter%20accurately,value%20for%20the%20metaField%20field.">https://www.mongodb.com/docs/v5.0/core/timeseries/timeseries-granularity/#:~:text=Setting%20the%20granularity%20parameter%20accurately,value%20for%20the%20metaField%20field.</a></figcaption></figure><h4>Chronological Ordered Data</h4><p>The most important rule is that the input data must be chronological ordered. If you need to handle not ordered data (as we did during the project) the Timeseries Collection is not the best choice, but you can use the Standard Collection. The reason behind this ordered assumption is based on the Timeseries bucket engine that is able to only handle only one bucket at a time. For example, if you have created the Timeseries Collection using “seconds” granularity, the timeseries bucket engine is able to only write documents with measure_time field that belong to the granularity time window. If you try to write a document with measure_time field greater or lower that the expected time window, the bucket engine close the bucket prematurly and create a new one empty bucket referring to the document measure_time. Therefore, in unordered chronological scenario there will be a lot of buckets with just a few documents for each. This assumption has big impact on reading and writing performances.</p><h4>Disk Space</h4><p>The principal advantage of the Timeseries Collection is the compression algorithm that is able to drastically reduce the disk space consumption. If you want to obtain similar performances also with Standard Collection, the best practice is to create the Standard Collection with the following command:</p><pre>db.createCollection(<br>&quot;test_standard_collection_name&quot;,<br>{ storageEngine: { wiredTiger: { configString: &quot;block_compressor=zstd&quot; } } }<br>)</pre><p>Also the indexes must be created specifing the storage engine configuration, as following:</p><pre>db[&quot;exdh_iot_tlm_org_harmonized_test_temp_2&quot;].createIndex({<br>&quot;field_1&quot;:1,<br>&quot;field_2&quot;:1,<br>&quot;field_3&quot;:1<br>}, { storageEngine: { wiredTiger: { configString: &quot;block_compressor=zstd&quot; } } }<br>)</pre><h4>No Update Operations</h4><p>One of the biggest limitations of Timeseries Collection is that you cannot edit or UpSert documents. The best practice is that if you require to update documents, you need to use Standard Collections.</p><p>In conclusion, in order to get the best performances from MongoDB Timeseries collections you should follow these 2 main principles:</p><ul><li>the input data must be chronological ordered</li><li>the ingestion rate period must be constant and must be aligned with the granularity parameter of the Timeseries Collection</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fa9d29405ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>