Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a text index on the 'description' field.
MongoDB
db.products.createIndex({ description: [1] }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 or -1 creates a normal ascending or descending index, not a text index.
Using "index" is not a valid index type.
✗ Incorrect
To create a text index in MongoDB, you specify the field with the value "text".
2fill in blank
mediumComplete the code to search for documents containing the word 'coffee' using the text index.
MongoDB
db.products.find({ $[1]: { $search: "coffee" } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $match or $search instead of $text causes errors.
Using $query is not valid for text search.
✗ Incorrect
The $text operator is used to perform text search queries in MongoDB.
3fill in blank
hardFix the error in the code to create a text index on both 'title' and 'content' fields.
MongoDB
db.articles.createIndex({ title: [1], content: [1] }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 or -1 for text indexes is incorrect.
Using different types for each field causes errors.
✗ Incorrect
Both fields must be set to "text" to create a compound text index.
4fill in blank
hardFill both blanks to perform a text search for 'mongodb' and sort results by text score.
MongoDB
db.blog.find({ $[1]: { $search: "mongodb" } }, { score: { $meta: [2] } }).sort({ score: { $meta: "textScore" } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $search instead of $text causes errors.
Using incorrect meta values like "score" or "searchScore" fails.
✗ Incorrect
Use $text for the search operator and $meta: "textScore" to get the relevance score.
5fill in blank
hardFill all three blanks to create a text index on 'summary', search for 'database', and project the text score.
MongoDB
db.reviews.createIndex({ [1]: [2] });
db.reviews.find({ $[3]: { $search: "database" } }, { score: { $meta: "textScore" } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong field names or index types.
Using $search instead of $text for the query.
✗ Incorrect
Create the index on 'summary' with type "text", then use $text to search.