A time-series collection is a special type of collection optimized to store and query data that changes over time, like sensor readings or logs, making it faster and more efficient for time-based data.
Click to reveal answer
beginner
Which two fields are used when creating a time-series collection in MongoDB?
The two fields are the timeField, which stores the timestamp of the data, and the metaField, which stores metadata about the data points.
Click to reveal answer
intermediate
How does MongoDB optimize storage for time-series collections?
MongoDB organizes data in time-series collections by grouping measurements into compressed internal buckets based on time intervals, reducing storage space and improving query speed.
Click to reveal answer
intermediate
Can you insert regular documents into a time-series collection in MongoDB?
No, time-series collections expect documents to follow a specific schema with a timeField and optional metaField. Regular documents without these fields will cause errors or unexpected behavior.
Click to reveal answer
beginner
What is the benefit of using the metaField in a time-series collection?
The metaField stores metadata that groups related measurements, like device ID or location, allowing efficient filtering and querying without duplicating data in every document.
Click to reveal answer
What is the purpose of the timeField in a MongoDB time-series collection?
ATo index the collection
BTo store the timestamp of each data point
CTo store metadata about the data
DTo store user information
✗ Incorrect
The timeField stores the timestamp for each measurement, which is essential for time-based queries.
Which command is used to create a time-series collection in MongoDB?
A. Missing required timeField in timeseries options
B. metaField cannot be used in time-series collections
C. Collection name is invalid
D. timeseries option is misspelled
Solution
Step 1: Check timeseries options in the command
The command specifies metaField but omits the required timeField.
Step 2: Recall MongoDB requirements
timeField is mandatory for time-series collections; missing it causes an error.
Final Answer:
Missing required timeField in timeseries options -> Option A
Quick Check:
timeField missing = error [OK]
Hint: Always include timeField when creating time-series collections [OK]
Common Mistakes:
Thinking metaField is not allowed
Assuming collection name is invalid
Believing timeseries option is misspelled
5. You have a time-series collection with fields timestamp (timeField) and sensorId (metaField). You want to query the average temperature for sensorId 'S1' over the last 24 hours. Which aggregation pipeline is correct?