SlideShare a Scribd company logo
1 of 41
Download to read offline
Time Series in MongoDB
Presented by
Chandrika Pokuri,
Mydbops
June 24th, 2023
Mydbops MyWebinar - 24
About Me
Chandrika
● Interested in MongoDB
● Performance Troubleshooting
● Blogger
Mydbops Services
Focus on MySQL,MongoDB,PostgreSQL
Consulting
Services
Consulting
Services
Managed
Services
24*7
DBA Team
Targeted
Engagement
Agenda
Introduction
Behavior Time Series
Managing Time Series Collections
Best Practices for Time Series Collections
Introduction
Time Series Use Case
What and Why Time Series Collection
❖ MongoDB Time Series Collection is a specialized feature introduced in MongoDB 5.0
❖ Time Series Collection in MongoDB: A specialized collection designed for efficient
storage and management and analysis of time series data.
Behavior Time Series
Benefits Of Time Series
Performance
Data Management
Space Management
Time Series Components
★ Time when the data point was recorded
★ Metadata also known as a source, is a label or tag
that uniquely identifies a time series and typically
remains unchanged throughout its lifespan.
★ Measurement is a data point tracked at
increments in time
Vestibulum congue
tempus
Lorem ipsum dolor sit amet,
consectetur adipiscing elit, sed do
eiusmod tempor. Donec facilisis
lacus eget mauris.
3
1
2
3
MetaData
TimeField
Measurement
Components
Creation Of Time Series Collection
Use the following command to create a time series collection
test:PRIMARY> db.createCollection("windsensors", { timeseries: { timeField: "ts",
metaField: "metadata", granularity: "seconds" } })
{
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1682983705, 3),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1682983705, 3)
}
Inserting Of Documents
Inserting of the documents in windsensors collection is same as normal collection.
db.windsensors.insertMany([
{"metadata":{"place":"Hyderabad", "sensorId":52396},"ts":ISODate("2023-06-20T10:00:02Z"),
"value" :18},
{"metadata":{"place":"Hyderabad", "sensorId":52396},"ts":ISODate("2023-06-20T10:02:03Z"),
"value":50}
])
Behavior Of Time Series : Granularity for Time Series Data
❖ "granularity" refers to the level of detail or precision at which time series data is stored and queried in a time
series collection. It determines the duration of each bucket or interval within the collection.
❖ Possible values are for granularity are "seconds","minutes","hours".
❖ It determines the maximum time span that a single bucket can cover.
Granularity Covered Time Span
seconds (default) one hour
minutes 24 hours
hours 30 days
Behavior Of Time Series : Granularity for Time Series Data
Change the granularity of a Time Series Collection
To change the granularity parameter value, issue the following collMod command
Once the granularity is set it can only be increased by one level at a time.
db.runCommand({collMod: "windsensors",timeseries: { granularity: "minutes" }})
Behavior Of Time Series: Materialized Views on Top of Time
Series Data
MongoDB treats time series collections as writable
non-materialized views, automatically organizing the
inserted data into an optimized storage format.
We can also create a materialised view.Materialized views
on time series data are useful for
❖ Archiving
❖ Analytics
❖ Facilitating data access for teams that cannot access
the raw data
Behavior Of Time Series: Materialized Views on Top of Time Series Data
Use the following command to create the On-demand materialized views.
The $match stage filters the data to process only those value greater than one
db.windsensors.aggregate( [
{ $match: {"value":{$gt:1}}},
{ $merge: { into: "windsensors_view", whenMatched: "replace" } }
] )
Behavior Of Time Series : Clustered Index
❖ Clustered collections are collections with a clustered
index.
❖ Clustered collections store documents ordered by
clustered index key value.
❖ clustered Indexes is best when you have equality or range
queries
Clustered Collection & Index Creation
This section shows clustered collection examples.
"key": { id: 1 }, which sets the clustered index key to the id field.
"unique": true, which indicates the clustered index key value must be unique.
"name": "windsensors clustered key", which sets the clustered index name.
db.runCommand( { create: "windsensors",
clusteredIndex: { "key": { id: 1 }, "unique": true, "name": "windsensors clustered key" }
} )
Limitations Of Clustered Index
● You cannot transform a non-clustered collection to a clustered collection, or the reverse.
● You cannot hide a clustered index.
● Clustered collections may not be capped collections.
Behavior Of Time Series : Sharding
Shard a Time Series Collection
To create a timeseries collection in sharding.Use the shardCollection() method with the timeseries option.
Limitation
➔ You can't reshard a sharded time series collection. However, you can refine its shard key.
sh.shardCollection("sample.windsensors",{ "metadata.sensorId": 1 },{timeseries:
{timeField: "ts",metaField: "metadata",granularity: "seconds"}})
Shard an Existing Time Series Collection
To shard the collection, run the following command
In this example, sh.shardCollection()
● Specifies the metadata.sensorId field as the shard key. sensorId is a sub-field of the collection's metaField.
● When the collection you specify to sh.shardCollection() is a time series collection, you do not need to specify
the timeseries option.
sh.shardCollection( "sample.windsensors_original", { "metadata.sensorId": 1 } )
Managing Time Series
Collections
Managing Time Series : Indexes in Time Series Collection
❖ The internal index provides several performance
benefits including improved query efficiency and
reduced disk usage.
❖ When you create a time series collection,
MongoDB automatically creates an internal
clustered index on the time field.
❖ The internal index for a time series collection is
not displayed by listIndexes.
Managing Time Series :Secondary Indexes to Time Series Collections
❖ Secondary indexes provide additional flexibility in querying and retrieving data
based on specific fields or criteria and improves query performance and enables
efficient data filtering and sorting.
❖ In MongoDB 5.0 and earlier, both the metaField and timeField can have
secondary indexes.
❖ Starting from MongoDB 6.0, you have the ability to create a secondary index on
any field or subfield.
Managing Time Series : expireAfterSeconds In Time Series
❖ To delete data after a specified period, use expireAfterSeconds field to automatically destroy documents
once they reach the expiration duration.
❖ The expiration threshold is the timeField field value plus the specified number of seconds.
db.createCollection(
"weather",
{
timeseries: {
timeField: "timestamp",
metaField: "metadata",
granularity: "hours"
},
expireAfterSeconds: 86400
}
)
Timing of Delete Operations
❖ The deletion worker runs for every 60 seconds and removes expired
buckets, and the maximum bucket duration is based on the
collection's granularity.
❖ Expired buckets are removed in the next run of the background task
once all documents within them have expired.
Enable Automatic Removal on a Existing Collection
To enable automatic removal of documents for an existing time series collection, issue the following collMod
command.
To retrieve the current value of expireAfterSeconds, use the listCollections command.
db.runCommand({collMod: "windsensors",expireAfterSeconds:86400})
db.runCommand( { listCollections: 1 } )
Change the expireAfterSeconds Parameter
To change the expireAfterSeconds parameter value, issue the following collMod
command.
Here we have changing the expireAfterSeconds from 86400 to 172800.
db.runCommand({collMod: "windsensors",expireAfterSeconds: 172800})
Disable Automatic Removal
To disable automatic removal, use the collMod command to set expireAfterSeconds to off.
db.runCommand({collMod: "windsensors",expireAfterSeconds: "off"})
Managing Time Series : Migrate Data into a Time Series Collection
To migrate data from an existing collection into a
time series collection
❖ Create a New Time Series Collection
❖ Dump of Data
❖ Migrate Data into a Time Series Collection
Time Series Uses Snappy
Compression???..
Time Series Compression
❖ Time series collections use zstd compression for efficient storage and retrieval of data.
❖ Starting in MongoDB 5.2, time series collections use column compression.
❖ Columnar compression is a technique used to compress data in a column-wise manner, rather than row-wise.
Columnar Compression
❖ Columnar compression works by storing data values from each
column together, rather than storing entire documents or rows.
❖ MongoDB supports columnar compression through the use of
the WiredTiger storage engine.
❖ WiredTiger uses a technique called "prefix compression" to
compress data in a column-oriented manner.
Best Practices for Time
Series Collections
Best Practices for Time Series Collections:Optimize Inserts
To optimize insert performance for time series collections, perform the following actions.
❖ Batch Documents by multiple measurements.
db.windsensors.insertMany([
{"metadata":{"place":"Hyderabad", "sensorId":52396},"ts":ISODate("2021-07-10T00:00:022"), "value"
:18.263742590570686},
{"metadata":{"place":"Chennai", "sensorId":31096},"ts":ISODate("2021-07-10700:00:03Z"),
"value":32.53987084180961},
{"metadata":{"place":"Hyderabad", "sensorId":52396},"ts":ISODate("2021-07-10T00:00:032"),
"value":18.106480571706808},
{"metadata":{"place":"Chennai", "sensorId":31096},"ts":ISODate("2021-07-10T00:00:04Z"),
"value":0.6909954039798452}
])
Best Practices for Time Series Collections:Optimize Compression
To optimize data compression for time series collections, perform the following actions.
➔ Omit Fields Containing Empty Objects and Arrays from Documents.
➔ Round numeric data to the precision required for your application. Rounding numeric data to fewer decimal
places improves the compression ratio.
Best Practices for Time Series Collections:Optimize Compression
For example, consider the following documents
The alternation between value fields with sensors values and an empty array result in a schema change for the
compressor. The schema change causes the second and third documents in the sequence remain uncompressed.
db.windsensors. insertMany([
{"metadata":{"place":"Hyderabad","sensorId":52396},"ts":ISODate("2021-07-10700:00:022"),
"value": [18,20]},
{"metadata":{"place":"Chennai","sensorld":31096},"ts":ISODate("2021-07-10700:00:032"),
"value": []},
{"metadata":{"place":"Hyderabad","sensorId":52396},"ts":ISODate("2021-07-10700:00:032"),
"value": [14,161]}
])
Limitations Of Time Series
The following features are not supported for time series collections
➔ Change streams
➔ Client-Side Field Level Encryption
➔ Database Triggers
➔ Schema validation rules
➔ reIndex
➔ renameCollection
➔ Modification of timeField and metaField
➔ Capped Collections
Time series in MongoDB - Mydbops
Time series in MongoDB - Mydbops

More Related Content

Similar to Time series in MongoDB - Mydbops

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBRaghunath A
 
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...DataStax
 
Tips, Tricks & Best Practices for large scale HDInsight Deployments
Tips, Tricks & Best Practices for large scale HDInsight DeploymentsTips, Tricks & Best Practices for large scale HDInsight Deployments
Tips, Tricks & Best Practices for large scale HDInsight DeploymentsAshish Thapliyal
 
Re-Engineering PostgreSQL as a Time-Series Database
Re-Engineering PostgreSQL as a Time-Series DatabaseRe-Engineering PostgreSQL as a Time-Series Database
Re-Engineering PostgreSQL as a Time-Series DatabaseAll Things Open
 
Chronix Time Series Database - The New Time Series Kid on the Block
Chronix Time Series Database - The New Time Series Kid on the BlockChronix Time Series Database - The New Time Series Kid on the Block
Chronix Time Series Database - The New Time Series Kid on the BlockQAware GmbH
 
Webinar: Was ist neu in MongoDB 2.4
Webinar: Was ist neu in MongoDB 2.4Webinar: Was ist neu in MongoDB 2.4
Webinar: Was ist neu in MongoDB 2.4MongoDB
 
Solving your Backup Needs - Ben Cefalo mdbe18
Solving your Backup Needs - Ben Cefalo mdbe18Solving your Backup Needs - Ben Cefalo mdbe18
Solving your Backup Needs - Ben Cefalo mdbe18MongoDB
 
OSDC 2016 - Chronix - A fast and efficient time series storage based on Apach...
OSDC 2016 - Chronix - A fast and efficient time series storage based on Apach...OSDC 2016 - Chronix - A fast and efficient time series storage based on Apach...
OSDC 2016 - Chronix - A fast and efficient time series storage based on Apach...NETWAYS
 
A Fast and Efficient Time Series Storage Based on Apache Solr
A Fast and Efficient Time Series Storage Based on Apache SolrA Fast and Efficient Time Series Storage Based on Apache Solr
A Fast and Efficient Time Series Storage Based on Apache SolrQAware GmbH
 
Chronix: A fast and efficient time series storage based on Apache Solr
Chronix: A fast and efficient time series storage based on Apache SolrChronix: A fast and efficient time series storage based on Apache Solr
Chronix: A fast and efficient time series storage based on Apache SolrFlorian Lautenschlager
 
Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21Stamatis Zampetakis
 
Indexing and Query Performance in MongoDB.pdf
Indexing and Query Performance in MongoDB.pdfIndexing and Query Performance in MongoDB.pdf
Indexing and Query Performance in MongoDB.pdfMalak Abu Hammad
 
MongoDB Sharding Webinar 2014
MongoDB Sharding Webinar 2014MongoDB Sharding Webinar 2014
MongoDB Sharding Webinar 2014Dylan Tong
 
Cassandra's Sweet Spot - an introduction to Apache Cassandra
Cassandra's Sweet Spot - an introduction to Apache CassandraCassandra's Sweet Spot - an introduction to Apache Cassandra
Cassandra's Sweet Spot - an introduction to Apache CassandraDave Gardner
 
MongoDB IoT City Tour LONDON: Managing the Database Complexity, by Arthur Vie...
MongoDB IoT City Tour LONDON: Managing the Database Complexity, by Arthur Vie...MongoDB IoT City Tour LONDON: Managing the Database Complexity, by Arthur Vie...
MongoDB IoT City Tour LONDON: Managing the Database Complexity, by Arthur Vie...MongoDB
 
How to Build a Multi-DC Cassandra Cluster in AWS with OpsCenter LCM
How to Build a Multi-DC Cassandra Cluster in AWS with OpsCenter LCMHow to Build a Multi-DC Cassandra Cluster in AWS with OpsCenter LCM
How to Build a Multi-DC Cassandra Cluster in AWS with OpsCenter LCMAnant Corporation
 
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCAndy Butland
 

Similar to Time series in MongoDB - Mydbops (20)

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
 
Tips, Tricks & Best Practices for large scale HDInsight Deployments
Tips, Tricks & Best Practices for large scale HDInsight DeploymentsTips, Tricks & Best Practices for large scale HDInsight Deployments
Tips, Tricks & Best Practices for large scale HDInsight Deployments
 
Re-Engineering PostgreSQL as a Time-Series Database
Re-Engineering PostgreSQL as a Time-Series DatabaseRe-Engineering PostgreSQL as a Time-Series Database
Re-Engineering PostgreSQL as a Time-Series Database
 
Chronix Time Series Database - The New Time Series Kid on the Block
Chronix Time Series Database - The New Time Series Kid on the BlockChronix Time Series Database - The New Time Series Kid on the Block
Chronix Time Series Database - The New Time Series Kid on the Block
 
The new time series kid on the block
The new time series kid on the blockThe new time series kid on the block
The new time series kid on the block
 
Webinar: Was ist neu in MongoDB 2.4
Webinar: Was ist neu in MongoDB 2.4Webinar: Was ist neu in MongoDB 2.4
Webinar: Was ist neu in MongoDB 2.4
 
Solving your Backup Needs - Ben Cefalo mdbe18
Solving your Backup Needs - Ben Cefalo mdbe18Solving your Backup Needs - Ben Cefalo mdbe18
Solving your Backup Needs - Ben Cefalo mdbe18
 
OSDC 2016 - Chronix - A fast and efficient time series storage based on Apach...
OSDC 2016 - Chronix - A fast and efficient time series storage based on Apach...OSDC 2016 - Chronix - A fast and efficient time series storage based on Apach...
OSDC 2016 - Chronix - A fast and efficient time series storage based on Apach...
 
A Fast and Efficient Time Series Storage Based on Apache Solr
A Fast and Efficient Time Series Storage Based on Apache SolrA Fast and Efficient Time Series Storage Based on Apache Solr
A Fast and Efficient Time Series Storage Based on Apache Solr
 
Chronix: A fast and efficient time series storage based on Apache Solr
Chronix: A fast and efficient time series storage based on Apache SolrChronix: A fast and efficient time series storage based on Apache Solr
Chronix: A fast and efficient time series storage based on Apache Solr
 
Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21
 
Mongodb
MongodbMongodb
Mongodb
 
Indexing and Query Performance in MongoDB.pdf
Indexing and Query Performance in MongoDB.pdfIndexing and Query Performance in MongoDB.pdf
Indexing and Query Performance in MongoDB.pdf
 
MongoDB Sharding Webinar 2014
MongoDB Sharding Webinar 2014MongoDB Sharding Webinar 2014
MongoDB Sharding Webinar 2014
 
Cassandra's Sweet Spot - an introduction to Apache Cassandra
Cassandra's Sweet Spot - an introduction to Apache CassandraCassandra's Sweet Spot - an introduction to Apache Cassandra
Cassandra's Sweet Spot - an introduction to Apache Cassandra
 
MongoDB IoT City Tour LONDON: Managing the Database Complexity, by Arthur Vie...
MongoDB IoT City Tour LONDON: Managing the Database Complexity, by Arthur Vie...MongoDB IoT City Tour LONDON: Managing the Database Complexity, by Arthur Vie...
MongoDB IoT City Tour LONDON: Managing the Database Complexity, by Arthur Vie...
 
MongoDB_ppt.pptx
MongoDB_ppt.pptxMongoDB_ppt.pptx
MongoDB_ppt.pptx
 
How to Build a Multi-DC Cassandra Cluster in AWS with OpsCenter LCM
How to Build a Multi-DC Cassandra Cluster in AWS with OpsCenter LCMHow to Build a Multi-DC Cassandra Cluster in AWS with OpsCenter LCM
How to Build a Multi-DC Cassandra Cluster in AWS with OpsCenter LCM
 
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVC
 

More from Mydbops

Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024Mydbops
 
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...Mydbops
 
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
Mastering Aurora PostgreSQL Clusters for Disaster RecoveryMastering Aurora PostgreSQL Clusters for Disaster Recovery
Mastering Aurora PostgreSQL Clusters for Disaster RecoveryMydbops
 
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...Mydbops
 
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15Mydbops
 
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE EventData-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE EventMydbops
 
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...Mydbops
 
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...Mydbops
 
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...Mydbops
 
Data Organisation: Table Partitioning in PostgreSQL
Data Organisation: Table Partitioning in PostgreSQLData Organisation: Table Partitioning in PostgreSQL
Data Organisation: Table Partitioning in PostgreSQLMydbops
 
Navigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
Navigating MongoDB's Queryable Encryption for Ultimate Security - MydbopsNavigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
Navigating MongoDB's Queryable Encryption for Ultimate Security - MydbopsMydbops
 
Data High Availability With TIDB
Data High Availability With TIDBData High Availability With TIDB
Data High Availability With TIDBMydbops
 
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...Mydbops
 
Enhancing Security of MySQL Connections using SSL certificates
Enhancing Security of MySQL Connections using SSL certificatesEnhancing Security of MySQL Connections using SSL certificates
Enhancing Security of MySQL Connections using SSL certificatesMydbops
 
Exploring the Fundamentals of YugabyteDB - Mydbops
Exploring the Fundamentals of YugabyteDB - Mydbops Exploring the Fundamentals of YugabyteDB - Mydbops
Exploring the Fundamentals of YugabyteDB - Mydbops Mydbops
 
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - MydbopsTiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - MydbopsMydbops
 
Achieving High Availability in PostgreSQL
Achieving High Availability in PostgreSQLAchieving High Availability in PostgreSQL
Achieving High Availability in PostgreSQLMydbops
 
Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding Mydbops
 
MySQL Data Encryption at Rest
MySQL Data Encryption at RestMySQL Data Encryption at Rest
MySQL Data Encryption at RestMydbops
 

More from Mydbops (20)

Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
 
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
 
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
Mastering Aurora PostgreSQL Clusters for Disaster RecoveryMastering Aurora PostgreSQL Clusters for Disaster Recovery
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
 
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
 
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
 
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE EventData-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
 
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
 
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
 
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
 
Data Organisation: Table Partitioning in PostgreSQL
Data Organisation: Table Partitioning in PostgreSQLData Organisation: Table Partitioning in PostgreSQL
Data Organisation: Table Partitioning in PostgreSQL
 
Navigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
Navigating MongoDB's Queryable Encryption for Ultimate Security - MydbopsNavigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
Navigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
 
Data High Availability With TIDB
Data High Availability With TIDBData High Availability With TIDB
Data High Availability With TIDB
 
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
 
Enhancing Security of MySQL Connections using SSL certificates
Enhancing Security of MySQL Connections using SSL certificatesEnhancing Security of MySQL Connections using SSL certificates
Enhancing Security of MySQL Connections using SSL certificates
 
Exploring the Fundamentals of YugabyteDB - Mydbops
Exploring the Fundamentals of YugabyteDB - Mydbops Exploring the Fundamentals of YugabyteDB - Mydbops
Exploring the Fundamentals of YugabyteDB - Mydbops
 
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - MydbopsTiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
 
Achieving High Availability in PostgreSQL
Achieving High Availability in PostgreSQLAchieving High Availability in PostgreSQL
Achieving High Availability in PostgreSQL
 
Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding
 
MySQL Data Encryption at Rest
MySQL Data Encryption at RestMySQL Data Encryption at Rest
MySQL Data Encryption at Rest
 

Recently uploaded

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Recently uploaded (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Time series in MongoDB - Mydbops

  • 1. Time Series in MongoDB Presented by Chandrika Pokuri, Mydbops June 24th, 2023 Mydbops MyWebinar - 24
  • 2. About Me Chandrika ● Interested in MongoDB ● Performance Troubleshooting ● Blogger
  • 3. Mydbops Services Focus on MySQL,MongoDB,PostgreSQL Consulting Services Consulting Services Managed Services 24*7 DBA Team Targeted Engagement
  • 4. Agenda Introduction Behavior Time Series Managing Time Series Collections Best Practices for Time Series Collections
  • 7. What and Why Time Series Collection ❖ MongoDB Time Series Collection is a specialized feature introduced in MongoDB 5.0 ❖ Time Series Collection in MongoDB: A specialized collection designed for efficient storage and management and analysis of time series data.
  • 9. Benefits Of Time Series Performance Data Management Space Management
  • 10. Time Series Components ★ Time when the data point was recorded ★ Metadata also known as a source, is a label or tag that uniquely identifies a time series and typically remains unchanged throughout its lifespan. ★ Measurement is a data point tracked at increments in time Vestibulum congue tempus Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Donec facilisis lacus eget mauris. 3 1 2 3 MetaData TimeField Measurement Components
  • 11. Creation Of Time Series Collection Use the following command to create a time series collection test:PRIMARY> db.createCollection("windsensors", { timeseries: { timeField: "ts", metaField: "metadata", granularity: "seconds" } }) { "ok" : 1, "$clusterTime" : { "clusterTime" : Timestamp(1682983705, 3), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } }, "operationTime" : Timestamp(1682983705, 3) }
  • 12. Inserting Of Documents Inserting of the documents in windsensors collection is same as normal collection. db.windsensors.insertMany([ {"metadata":{"place":"Hyderabad", "sensorId":52396},"ts":ISODate("2023-06-20T10:00:02Z"), "value" :18}, {"metadata":{"place":"Hyderabad", "sensorId":52396},"ts":ISODate("2023-06-20T10:02:03Z"), "value":50} ])
  • 13. Behavior Of Time Series : Granularity for Time Series Data ❖ "granularity" refers to the level of detail or precision at which time series data is stored and queried in a time series collection. It determines the duration of each bucket or interval within the collection. ❖ Possible values are for granularity are "seconds","minutes","hours". ❖ It determines the maximum time span that a single bucket can cover. Granularity Covered Time Span seconds (default) one hour minutes 24 hours hours 30 days
  • 14. Behavior Of Time Series : Granularity for Time Series Data
  • 15. Change the granularity of a Time Series Collection To change the granularity parameter value, issue the following collMod command Once the granularity is set it can only be increased by one level at a time. db.runCommand({collMod: "windsensors",timeseries: { granularity: "minutes" }})
  • 16. Behavior Of Time Series: Materialized Views on Top of Time Series Data MongoDB treats time series collections as writable non-materialized views, automatically organizing the inserted data into an optimized storage format. We can also create a materialised view.Materialized views on time series data are useful for ❖ Archiving ❖ Analytics ❖ Facilitating data access for teams that cannot access the raw data
  • 17. Behavior Of Time Series: Materialized Views on Top of Time Series Data Use the following command to create the On-demand materialized views. The $match stage filters the data to process only those value greater than one db.windsensors.aggregate( [ { $match: {"value":{$gt:1}}}, { $merge: { into: "windsensors_view", whenMatched: "replace" } } ] )
  • 18. Behavior Of Time Series : Clustered Index ❖ Clustered collections are collections with a clustered index. ❖ Clustered collections store documents ordered by clustered index key value. ❖ clustered Indexes is best when you have equality or range queries
  • 19. Clustered Collection & Index Creation This section shows clustered collection examples. "key": { id: 1 }, which sets the clustered index key to the id field. "unique": true, which indicates the clustered index key value must be unique. "name": "windsensors clustered key", which sets the clustered index name. db.runCommand( { create: "windsensors", clusteredIndex: { "key": { id: 1 }, "unique": true, "name": "windsensors clustered key" } } )
  • 20. Limitations Of Clustered Index ● You cannot transform a non-clustered collection to a clustered collection, or the reverse. ● You cannot hide a clustered index. ● Clustered collections may not be capped collections.
  • 21. Behavior Of Time Series : Sharding Shard a Time Series Collection To create a timeseries collection in sharding.Use the shardCollection() method with the timeseries option. Limitation ➔ You can't reshard a sharded time series collection. However, you can refine its shard key. sh.shardCollection("sample.windsensors",{ "metadata.sensorId": 1 },{timeseries: {timeField: "ts",metaField: "metadata",granularity: "seconds"}})
  • 22. Shard an Existing Time Series Collection To shard the collection, run the following command In this example, sh.shardCollection() ● Specifies the metadata.sensorId field as the shard key. sensorId is a sub-field of the collection's metaField. ● When the collection you specify to sh.shardCollection() is a time series collection, you do not need to specify the timeseries option. sh.shardCollection( "sample.windsensors_original", { "metadata.sensorId": 1 } )
  • 24. Managing Time Series : Indexes in Time Series Collection ❖ The internal index provides several performance benefits including improved query efficiency and reduced disk usage. ❖ When you create a time series collection, MongoDB automatically creates an internal clustered index on the time field. ❖ The internal index for a time series collection is not displayed by listIndexes.
  • 25. Managing Time Series :Secondary Indexes to Time Series Collections ❖ Secondary indexes provide additional flexibility in querying and retrieving data based on specific fields or criteria and improves query performance and enables efficient data filtering and sorting. ❖ In MongoDB 5.0 and earlier, both the metaField and timeField can have secondary indexes. ❖ Starting from MongoDB 6.0, you have the ability to create a secondary index on any field or subfield.
  • 26. Managing Time Series : expireAfterSeconds In Time Series ❖ To delete data after a specified period, use expireAfterSeconds field to automatically destroy documents once they reach the expiration duration. ❖ The expiration threshold is the timeField field value plus the specified number of seconds. db.createCollection( "weather", { timeseries: { timeField: "timestamp", metaField: "metadata", granularity: "hours" }, expireAfterSeconds: 86400 } )
  • 27. Timing of Delete Operations ❖ The deletion worker runs for every 60 seconds and removes expired buckets, and the maximum bucket duration is based on the collection's granularity. ❖ Expired buckets are removed in the next run of the background task once all documents within them have expired.
  • 28. Enable Automatic Removal on a Existing Collection To enable automatic removal of documents for an existing time series collection, issue the following collMod command. To retrieve the current value of expireAfterSeconds, use the listCollections command. db.runCommand({collMod: "windsensors",expireAfterSeconds:86400}) db.runCommand( { listCollections: 1 } )
  • 29. Change the expireAfterSeconds Parameter To change the expireAfterSeconds parameter value, issue the following collMod command. Here we have changing the expireAfterSeconds from 86400 to 172800. db.runCommand({collMod: "windsensors",expireAfterSeconds: 172800})
  • 30. Disable Automatic Removal To disable automatic removal, use the collMod command to set expireAfterSeconds to off. db.runCommand({collMod: "windsensors",expireAfterSeconds: "off"})
  • 31. Managing Time Series : Migrate Data into a Time Series Collection To migrate data from an existing collection into a time series collection ❖ Create a New Time Series Collection ❖ Dump of Data ❖ Migrate Data into a Time Series Collection
  • 32. Time Series Uses Snappy Compression???..
  • 33. Time Series Compression ❖ Time series collections use zstd compression for efficient storage and retrieval of data. ❖ Starting in MongoDB 5.2, time series collections use column compression. ❖ Columnar compression is a technique used to compress data in a column-wise manner, rather than row-wise.
  • 34. Columnar Compression ❖ Columnar compression works by storing data values from each column together, rather than storing entire documents or rows. ❖ MongoDB supports columnar compression through the use of the WiredTiger storage engine. ❖ WiredTiger uses a technique called "prefix compression" to compress data in a column-oriented manner.
  • 35. Best Practices for Time Series Collections
  • 36. Best Practices for Time Series Collections:Optimize Inserts To optimize insert performance for time series collections, perform the following actions. ❖ Batch Documents by multiple measurements. db.windsensors.insertMany([ {"metadata":{"place":"Hyderabad", "sensorId":52396},"ts":ISODate("2021-07-10T00:00:022"), "value" :18.263742590570686}, {"metadata":{"place":"Chennai", "sensorId":31096},"ts":ISODate("2021-07-10700:00:03Z"), "value":32.53987084180961}, {"metadata":{"place":"Hyderabad", "sensorId":52396},"ts":ISODate("2021-07-10T00:00:032"), "value":18.106480571706808}, {"metadata":{"place":"Chennai", "sensorId":31096},"ts":ISODate("2021-07-10T00:00:04Z"), "value":0.6909954039798452} ])
  • 37. Best Practices for Time Series Collections:Optimize Compression To optimize data compression for time series collections, perform the following actions. ➔ Omit Fields Containing Empty Objects and Arrays from Documents. ➔ Round numeric data to the precision required for your application. Rounding numeric data to fewer decimal places improves the compression ratio.
  • 38. Best Practices for Time Series Collections:Optimize Compression For example, consider the following documents The alternation between value fields with sensors values and an empty array result in a schema change for the compressor. The schema change causes the second and third documents in the sequence remain uncompressed. db.windsensors. insertMany([ {"metadata":{"place":"Hyderabad","sensorId":52396},"ts":ISODate("2021-07-10700:00:022"), "value": [18,20]}, {"metadata":{"place":"Chennai","sensorld":31096},"ts":ISODate("2021-07-10700:00:032"), "value": []}, {"metadata":{"place":"Hyderabad","sensorId":52396},"ts":ISODate("2021-07-10700:00:032"), "value": [14,161]} ])
  • 39. Limitations Of Time Series The following features are not supported for time series collections ➔ Change streams ➔ Client-Side Field Level Encryption ➔ Database Triggers ➔ Schema validation rules ➔ reIndex ➔ renameCollection ➔ Modification of timeField and metaField ➔ Capped Collections