0
0
MongoDBquery~10 mins

Date expressions ($year, $month, $dayOfMonth) in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Ayear
Bmonth
CdayOfMonth
Dhour
Attempts:
3 left
💡 Hint
Common Mistakes
Using $month or $dayOfMonth instead of $year.
Forgetting the $ sign before the operator.
2fill in blank
medium

Complete 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'
AdayOfMonth
Bmonth
Cyear
Dminute
Attempts:
3 left
💡 Hint
Common Mistakes
Using $dayOfMonth or $year instead of $month.
Confusing month with minute or hour.
3fill in blank
hard

Fix 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'
Adate
Bmonth
CdayOfMonth
Dday
Attempts:
3 left
💡 Hint
Common Mistakes
Using $day or $date which are not valid operators.
Using $month instead of $dayOfMonth.
4fill in blank
hard

Fill 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'
Ayear
BdayOfMonth
Cmonth
Dhour
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping year and month operators.
Using $dayOfMonth or $hour instead of month.
5fill in blank
hard

Fill 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'
Ayear
Bmonth
CdayOfMonth
Dminute
Attempts:
3 left
💡 Hint
Common Mistakes
Using $day or $date instead of $dayOfMonth.
Mixing up month and dayOfMonth operators.