0
0
MongoDBquery~10 mins

Time-series collections in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a time-series collection named 'sensorData'.

MongoDB
db.createCollection('sensorData', { [1]: { timeField: 'timestamp', metaField: 'deviceId', granularity: 'seconds' } })
Drag options to blanks, or click blank then click option'
Atimeseries
BtimeSeries
Ctime_series
Dtime-series
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase like 'timeSeries' instead of 'timeseries'.
Adding underscores or hyphens in the option name.
2fill in blank
medium

Complete the code to insert a document with a timestamp and metadata into the 'sensorData' collection.

MongoDB
db.sensorData.insertOne({ timestamp: new Date(), [1]: 'device123', temperature: 22.5 })
Drag options to blanks, or click blank then click option'
Ameta
BmetaField
Cmetadata
DdeviceId
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'meta' or 'metadata' instead of the exact metaField name.
Using 'metaField' as a field name in the document.
3fill in blank
hard

Fix the error in the query to find documents where temperature is greater than 20.

MongoDB
db.sensorData.find({ temperature: { [1]: 20 } })
Drag options to blanks, or click blank then click option'
A$lt
B$gte
C$gt
D$lte
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt or $lte which mean less than.
Using $gte which means greater than or equal, not strictly greater.
4fill in blank
hard

Fill both blanks to create an aggregation pipeline that groups data by deviceId and calculates average temperature.

MongoDB
db.sensorData.aggregate([ { $group: { _id: '[1]', avgTemp: { $avg: '[2]' } } } ])
Drag options to blanks, or click blank then click option'
AdeviceId
Btemperature
Ctimestamp
Dmeta
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by timestamp instead of deviceId.
Averaging the wrong field like timestamp or meta.
5fill in blank
hard

Fill all three blanks to create a time-series collection with a custom granularity and insert a sample document.

MongoDB
db.createCollection('weatherData', { [1]: { timeField: '[2]', metaField: '[3]', granularity: 'minutes' } })
Drag options to blanks, or click blank then click option'
Atimeseries
BrecordedAt
Clocation
DtimeSeries
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'timeSeries' instead of 'timeseries' for the option name.
Mixing up the timeField and metaField names.