Challenge - 5 Problems
Text Search Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Find documents matching a text search
Given a MongoDB collection
Assume the collection has these documents:
articles with a text index on the content field, what will be the output of this query?db.articles.find({ $text: { $search: "coffee" } })Assume the collection has these documents:
[{ _id: 1, content: "I love coffee and tea." }, { _id: 2, content: "Tea is great." }, { _id: 3, content: "Coffee is energizing." }]MongoDB
db.articles.find({ $text: { $search: "coffee" } })Attempts:
2 left
💡 Hint
Text search matches documents containing the search word in the indexed fields.
✗ Incorrect
The text search for "coffee" matches documents where the content field contains the word "coffee" (case-insensitive). Documents 1 and 3 contain "coffee", document 2 does not.
🧠 Conceptual
intermediate1:30remaining
Understanding text index weights
In MongoDB, when creating a text index on multiple fields with different weights, what effect do the weights have on text search results?
Attempts:
2 left
💡 Hint
Think about how search results are ranked by relevance.
✗ Incorrect
Weights assign importance to fields so that matches in higher weighted fields increase the document's relevance score, affecting the order of results.
📝 Syntax
advanced1:30remaining
Correct syntax for creating a text index on multiple fields
Which of the following commands correctly creates a text index on the fields
title and description in a MongoDB collection products?Attempts:
2 left
💡 Hint
Text index type must be a string.
✗ Incorrect
The correct syntax uses strings "text" to specify the index type for each field. Option C uses double quotes correctly. Option C uses single quotes which is valid in JavaScript but double quotes are preferred for consistency.
❓ optimization
advanced2:00remaining
Improving text search performance with index filters
You have a large MongoDB collection with a text index on the
comments field. You want to speed up text searches by limiting the index to documents where status is "active". Which approach achieves this?Attempts:
2 left
💡 Hint
Partial indexes index only documents matching a filter.
✗ Incorrect
Partial text indexes index only documents matching the filter, reducing index size and improving search speed for queries filtering on status.
🔧 Debug
expert2:00remaining
Why does this text search query return no results?
You created a text index on the
But it returns no documents. Why?
summary field of a MongoDB collection. You run this query:db.books.find({ $text: { $search: "" } })But it returns no documents. Why?
Attempts:
2 left
💡 Hint
Think about what an empty search string means for matching.
✗ Incorrect
An empty $search string means no search terms are provided, so no documents match the query.