Recall & Review
beginner
What is the MongoDB data type used to store dates and times?
MongoDB uses the
Date type to store dates and times. It stores the number of milliseconds since the Unix epoch (January 1, 1970).Click to reveal answer
beginner
How do you create a new Date object in MongoDB shell?
You create a new Date object by calling
new Date(). For example, new Date() returns the current date and time.Click to reveal answer
intermediate
What is the difference between
Date and Timestamp types in MongoDB?Date stores a specific point in time with millisecond precision. Timestamp is mainly used internally for replication and stores a 64-bit value with a seconds part and an increment part.Click to reveal answer
beginner
How can you query documents with a date field greater than January 1, 2023?
Use a query like
{ dateField: { $gt: new Date('2023-01-01T00:00:00Z') } } to find documents where dateField is after January 1, 2023.Click to reveal answer
intermediate
Why is it important to store dates in UTC in MongoDB?
Storing dates in UTC avoids confusion caused by time zones and daylight saving changes. It ensures consistent date and time values across different systems and locations.
Click to reveal answer
Which MongoDB type stores date and time with millisecond precision?
✗ Incorrect
The Date type stores date and time with millisecond precision in MongoDB.
How do you create a Date object for the current time in MongoDB shell?
✗ Incorrect
new Date() creates a new Date object with the current date and time.
What is the main use of the
Timestamp type in MongoDB?✗ Incorrect
Timestamp is mainly used internally for replication and oplog entries in MongoDB.
Which query finds documents with a date after January 1, 2023?
✗ Incorrect
Use $gt with a Date object to find dates greater than January 1, 2023.
Why should dates be stored in UTC in MongoDB?
✗ Incorrect
Storing dates in UTC avoids confusion caused by time zones and daylight saving changes.
Explain the difference between MongoDB's Date and Timestamp types and when to use each.
Think about precision and internal MongoDB operations.
You got /4 concepts.
Describe how to query documents by date in MongoDB and why storing dates in UTC is important.
Consider query syntax and time zone handling.
You got /4 concepts.