0
0
MongoDBquery~10 mins

Type conversion expressions ($toInt, $toString) 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 convert the field 'age' to an integer using $toInt.

MongoDB
{ $project: { ageInt: { [1]: "$age" } } }
Drag options to blanks, or click blank then click option'
A$toString
B$toDate
C$toDouble
D$toInt
Attempts:
3 left
💡 Hint
Common Mistakes
Using $toString instead of $toInt.
Using $toDouble which converts to double, not integer.
2fill in blank
medium

Complete the code to convert the field 'score' to a string using $toString.

MongoDB
{ $project: { scoreStr: { [1]: "$score" } } }
Drag options to blanks, or click blank then click option'
A$toString
B$toInt
C$toBool
D$toDecimal
Attempts:
3 left
💡 Hint
Common Mistakes
Using $toInt which converts to integer, not string.
Using $toBool which converts to boolean, not string.
3fill in blank
hard

Fix the error in the code to convert 'price' to integer using $toInt.

MongoDB
{ $project: { priceInt: { [1]: "price" } } }
Drag options to blanks, or click blank then click option'
A$toString
B$toInt
C$toDouble
D$toDate
Attempts:
3 left
💡 Hint
Common Mistakes
Not prefixing the field name with '$'.
Using $toString instead of $toInt.
4fill in blank
hard

Fill both blanks to convert 'quantity' to integer and 'description' to string.

MongoDB
{ $project: { qtyInt: { [1]: "$quantity" }, descStr: { [2]: "$description" } } }
Drag options to blanks, or click blank then click option'
A$toInt
B$toString
C$toDouble
D$toBool
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the operators for the fields.
Using $toDouble or $toBool incorrectly.
5fill in blank
hard

Fill all three blanks to convert 'height' to integer, 'weight' to string, and 'active' to boolean.

MongoDB
{ $project: { heightInt: { [1]: "$height" }, weightStr: { [2]: "$weight" }, isActive: { [3]: "$active" } } }
Drag options to blanks, or click blank then click option'
A$toInt
B$toString
C$toBool
D$toDouble
Attempts:
3 left
💡 Hint
Common Mistakes
Using $toDouble instead of $toBool for boolean conversion.
Mixing up $toInt and $toString.