0
0
MongoDBquery~20 mins

Time-series collections in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Time-series Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Querying time-series data with a time filter
Given a MongoDB time-series collection named sensorData with documents containing timestamp and temperature fields, what will be the output of this query?

db.sensorData.find({ timestamp: { $gte: ISODate('2024-01-01T00:00:00Z'), $lt: ISODate('2024-01-02T00:00:00Z') } })

Assume the collection has 3 documents with timestamps on 2023-12-31, 2024-01-01, and 2024-01-02.
MongoDB
db.sensorData.find({ timestamp: { $gte: ISODate('2024-01-01T00:00:00Z'), $lt: ISODate('2024-01-02T00:00:00Z') } })
AReturns no documents
BReturns documents with timestamps on 2024-01-01 and 2024-01-02
CReturns only the document with timestamp on 2024-01-01
DReturns all three documents
Attempts:
2 left
💡 Hint
Think about the meaning of $gte and $lt in the time range filter.
🧠 Conceptual
intermediate
2:00remaining
Understanding time-series collection schema requirements
Which of the following is required when creating a time-series collection in MongoDB?
MongoDB
db.createCollection('sensorData', { timeseries: { timeField: 'timestamp', metaField: 'deviceId' } })
AThe <code>timeField</code> must be specified and contain date values
BThe <code>metaField</code> must be specified and contain numeric values
CThe collection must have an index on the <code>timeField</code> before creation
DThe collection must be capped
Attempts:
2 left
💡 Hint
Think about what MongoDB uses to organize time-series data.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in time-series collection creation
Which option contains a syntax error when creating a time-series collection named weatherData with recordedAt as the time field?
Adb.createCollection('weatherData', { timeseries: { timeField: 'recordedAt', metaField: 123 } })
Bdb.createCollection('weatherData', { timeseries: { timeField: 'recordedAt' } })
Cdb.createCollection('weatherData', { timeseries: { timeField: 'recordedAt', metaField: 'location' } })
Ddb.createCollection('weatherData', { timeseries: { timeField: 'recordedAt', granularity: 'minutes' } })
Attempts:
2 left
💡 Hint
Check the type of the metaField value.
optimization
advanced
2:00remaining
Optimizing queries on time-series collections
You want to optimize queries filtering by device ID and time range on a time-series collection sensorReadings. Which index strategy is best?
ANo indexes needed because time-series collections are always optimized
BCreate a compound index on <code>{ deviceId: 1, timestamp: 1 }</code>
CCreate a single index on <code>timestamp</code> only
DCreate a single index on <code>deviceId</code> only
Attempts:
2 left
💡 Hint
Think about filtering by both device and time.
🔧 Debug
expert
2:00remaining
Why does this time-series query return no results?
You run this query on a time-series collection tempLogs:

db.tempLogs.find({ timestamp: { $gt: new Date('2024-01-01T00:00:00Z') } })

But it returns no documents, even though you know data exists after that date. What is the most likely reason?
MongoDB
db.tempLogs.find({ timestamp: { $gt: new Date('2024-01-01T00:00:00Z') } })
AThe collection is empty
BThe query syntax is invalid and causes an error
CThe dates in the collection are stored as strings, not dates
DThe <code>timestamp</code> field is not the timeField defined in the collection
Attempts:
2 left
💡 Hint
Check the collection's timeField configuration.