
Make the results more presentable with meaningful field namesĮxecute an aggregation using the pipeline to calculate the energy an air-conditioning unit has consumed over the last hour for each reading received and also view its explain plan: db.device_readings.aggregate(pipelineRawReadings) ĭb.device_readings.explain("executionStats").aggregate(pipelineRawReadings) Įxecute an aggregation using the pipeline to compute the total energy consumed by all the air-conditioning units combined in each building for every hour and also view its explain plan: db.device_readings.aggregate(pipelineBuildingsSummary) ĭb.device_readings.explain("executionStats"). Sort the results by each building and then by each hourly summary Create compound index to aid performance for partitionBy & sortBy of setWindowFieldsĭb.device_readings.createIndex(, For InnoDB tables the recordsinrange method reads the b-tree leaf node that contains the first and last index entries that satisfy the predicates and then estimates the amount of data.
#THE MONGO DB OPTIMIZER IS OPTIMAL FULL#
NOTE: This command can be commented out and the full example will still work The optimizer must figure out the best index and calls the recordsinrange method to determine the selectivity of the query predicates for each relevant index. Use a time-series collection for optimal processing Sample Data Populationĭrop any old version of the database (if it exists) and then populate a new device_readings collection with device readings spanning 3 hours of a day for air-conditioning units in two different buildings. Furthermore, you want to compute the total energy consumed by all the air-conditioning units combined in each building for every hour. You want to analyse this data to see how much energy in kilowatt-hours (kWh) each air-conditioning unit has consumed over the last hour for each reading received. Every 30 minutes, a device in each unit sends the unit's current power consumption reading back to base, which a central database persists.

You are monitoring various air-conditioning units running in two buildings on an industrial campus.
#THE MONGO DB OPTIMIZER IS OPTIMAL SERIES#
Minimum MongoDB Version: 5.0 (due to use of time series collections, $setWindowFields stage & $integral operator) Scenario

Summarising Arrays For First, Last, Min, Max & Average Advanced Use Of Expressions For Array Processing

Embrace Composability For Increased Productivity
