0
0
MongoDBquery~10 mins

Text search with text indexes 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 create a text index on the 'description' field.

MongoDB
db.products.createIndex({ description: [1] })
Drag options to blanks, or click blank then click option'
A"text"
B-1
C1
D"index"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 or -1 instead of "text" for the index type.
Using "index" which is not a valid index type.
2fill in blank
medium

Complete the code to perform a text search for the word 'coffee' in the 'products' collection.

MongoDB
db.products.find({ $[1]: { $search: "coffee" } })
Drag options to blanks, or click blank then click option'
Asearch
Bmatch
Ctext
Dfilter
Attempts:
3 left
💡 Hint
Common Mistakes
Using $match or $search instead of $text.
Omitting the dollar sign before the operator.
3fill in blank
hard

Fix the error in the query to search for 'tea' and sort results by text score.

MongoDB
db.products.find({ $text: { $search: "tea" } }).sort({ [1]: { $meta: "textScore" } })
Drag options to blanks, or click blank then click option'
Atext_score
Bscore
CtextScore
DscoreText
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'textScore' or other incorrect field names instead of 'score'.
Not using $meta operator inside sort.
4fill in blank
hard

Fill both blanks to project the text score and sort results by it.

MongoDB
db.products.find({ $text: { $search: "juice" } }, { [1]: { $meta: "textScore" } }).sort({ [2]: { $meta: "textScore" } })
Drag options to blanks, or click blank then click option'
Ascore
BtextScore
Crating
Dpopularity
Attempts:
3 left
💡 Hint
Common Mistakes
Using different field names for projection and sorting.
Using fields unrelated to text score like 'rating' or 'popularity'.
5fill in blank
hard

Fill all three blanks to create a text index on 'title' and 'content', search for 'summer', and project the text score.

MongoDB
db.articles.createIndex({ [1]: "text", [2]: "text" });
db.articles.find({ $text: { $search: "summer" } }, { [3]: { $meta: "textScore" } })
Drag options to blanks, or click blank then click option'
Atitle
Bcontent
Cscore
Dauthor
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong field names for index or projection.
Forgetting to specify "text" as the index type.