Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to extract the year from the date field.
MongoDB
{ $project: { year: { $[1]: "$date" } } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $month or $dayOfMonth instead of $year.
Forgetting the $ sign before the operator.
✗ Incorrect
The $year operator extracts the year part from a date.
2fill in blank
mediumComplete the code to extract the month from the date field.
MongoDB
{ $project: { month: { $[1]: "$date" } } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $dayOfMonth or $year instead of $month.
Confusing month with minute or hour.
✗ Incorrect
The $month operator extracts the month number (1-12) from a date.
3fill in blank
hardFix the error in the code to extract the day of the month from the date field.
MongoDB
{ $project: { day: { $[1]: "$date" } } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $day or $date which are not valid operators.
Using $month instead of $dayOfMonth.
✗ Incorrect
The correct operator to get the day of the month is $dayOfMonth.
4fill in blank
hardFill both blanks to extract the year and month from the date field.
MongoDB
{ $project: { year: { $[1]: "$date" }, month: { $[2]: "$date" } } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping year and month operators.
Using $dayOfMonth or $hour instead of month.
✗ Incorrect
Use $year to get the year and $month to get the month from a date.
5fill in blank
hardFill all three blanks to extract year, month, and day of the month from the date field.
MongoDB
{ $project: { year: { $[1]: "$date" }, month: { $[2]: "$date" }, day: { $[3]: "$date" } } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $day or $date instead of $dayOfMonth.
Mixing up month and dayOfMonth operators.
✗ Incorrect
Use $year, $month, and $dayOfMonth to extract the respective parts from a date.