Challenge - 5 Problems
Time-series Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Querying time-series data with a time filter
Given a MongoDB time-series collection named sensorData with documents containing
Assume the collection has 3 documents with timestamps on 2023-12-31, 2024-01-01, and 2024-01-02.
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') } })Attempts:
2 left
💡 Hint
Think about the meaning of $gte and $lt in the time range filter.
✗ Incorrect
The query filters documents where timestamp is greater than or equal to 2024-01-01 and less than 2024-01-02. So only documents on 2024-01-01 are included, excluding 2024-01-02.
🧠 Conceptual
intermediate2: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' } })
Attempts:
2 left
💡 Hint
Think about what MongoDB uses to organize time-series data.
✗ Incorrect
The
timeField is mandatory and must contain date/time values to store time-series data properly. The metaField is optional and can contain any metadata.📝 Syntax
advanced2: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?Attempts:
2 left
💡 Hint
Check the type of the metaField value.
✗ Incorrect
The
metaField must be a string naming the metadata field. Using a number like 123 causes a syntax error.❓ optimization
advanced2: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?Attempts:
2 left
💡 Hint
Think about filtering by both device and time.
✗ Incorrect
A compound index on
deviceId and timestamp helps queries filter efficiently by both fields.🔧 Debug
expert2:00remaining
Why does this time-series query return no results?
You run this query on a time-series collection
But it returns no documents, even though you know data exists after that date. What is the most likely reason?
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') } })Attempts:
2 left
💡 Hint
Check the collection's timeField configuration.
✗ Incorrect
Time-series collections only index and query efficiently on the defined timeField. If
timestamp is not the timeField, queries on it return no results.