Complete the code to create a time-series collection named 'sensorData'.
db.createCollection('sensorData', { [1]: { timeField: 'timestamp', metaField: 'deviceId', granularity: 'seconds' } })
The correct option is timeseries. This is the exact option name MongoDB expects to create a time-series collection.
Complete the code to insert a document with a timestamp and metadata into the 'sensorData' collection.
db.sensorData.insertOne({ timestamp: new Date(), [1]: 'device123', temperature: 22.5 })The metadata field is named deviceId as defined in the collection options. This field stores device identification info.
Fix the error in the query to find documents where temperature is greater than 20.
db.sensorData.find({ temperature: { [1]: 20 } })The operator $gt means 'greater than'. It correctly filters documents with temperature above 20.
Fill both blanks to create an aggregation pipeline that groups data by deviceId and calculates average temperature.
db.sensorData.aggregate([ { $group: { _id: '[1]', avgTemp: { $avg: '[2]' } } } ])The _id field groups by deviceId. The average is calculated on the temperature field.
Fill all three blanks to create a time-series collection with a custom granularity and insert a sample document.
db.createCollection('weatherData', { [1]: { timeField: '[2]', metaField: '[3]', granularity: 'minutes' } })
The collection option is timeseries. The time field is recordedAt and the metadata field is location.