Recall & Review
beginner
What does the
$year date expression do in MongoDB?The
$year expression extracts the year part from a date value in MongoDB documents.Click to reveal answer
beginner
How does
$month work in MongoDB date expressions?The
$month expression extracts the month (1-12) from a date value in MongoDB documents.Click to reveal answer
beginner
What value range does
$dayOfMonth return in MongoDB?$dayOfMonth returns the day of the month as a number from 1 to 31, based on the date value.Click to reveal answer
intermediate
Write a MongoDB aggregation snippet to get the year from a field called
createdAt.Use
{ $year: "$createdAt" } inside a $project or $addFields stage to extract the year.Click to reveal answer
intermediate
Why are date expressions like
$year, $month, and $dayOfMonth useful in MongoDB?They help break down dates into parts for filtering, grouping, or formatting data easily in aggregation pipelines.
Click to reveal answer
What does
{ $month: "$dateField" } return in MongoDB?✗ Incorrect
$month extracts the month number (1 to 12) from a date value.
Which expression extracts the day of the month from a date in MongoDB?
✗ Incorrect
$dayOfMonth returns the day number (1-31) of the month from a date.
If a date is '2024-06-15', what will
{ $year: "$date" } return?✗ Incorrect
$year extracts the year part, so it returns 2024.
Which MongoDB stage commonly uses
$year, $month, and $dayOfMonth?✗ Incorrect
These expressions can be used in $match, $group, and $project stages for filtering, grouping, or reshaping data.
What is the valid range of values returned by
$month in MongoDB?✗ Incorrect
$month returns months numbered 1 through 12.
Explain how to extract the year, month, and day from a date field in MongoDB aggregation.
Think about breaking down a date into parts using MongoDB expressions.
You got /4 concepts.
Describe a real-life scenario where extracting year, month, and day from dates in MongoDB would be helpful.
Consider how businesses analyze data over time.
You got /4 concepts.