0
0
MongoDBquery~5 mins

Text indexes for search in MongoDB - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a text index in MongoDB?
A text index in MongoDB allows you to perform efficient text search on string content within documents. It indexes the text fields to quickly find documents matching search terms.
Click to reveal answer
beginner
How do you create a text index on a field named 'description' in MongoDB?
Use the command: <br>db.collection.createIndex({ description: "text" })<br>This creates a text index on the 'description' field for text search.
Click to reveal answer
beginner
What operator is used to perform a text search query in MongoDB?
The $text operator is used in the query to search text indexed fields. For example: { $text: { $search: "keyword" } }
Click to reveal answer
intermediate
Can you create a text index on multiple fields in MongoDB? How?
Yes, you can create a text index on multiple fields by specifying them with the value "text" in the index. For example:<br>db.collection.createIndex({ title: "text", description: "text" })
Click to reveal answer
intermediate
What is the effect of the $language option in a text search query?
The $language option sets the language for the search to apply language-specific rules like stemming and stop words. For example, { $text: { $search: "run", $language: "english" } }.
Click to reveal answer
Which MongoDB command creates a text index on the 'content' field?
Adb.collection.createIndex({ content: 1 })
Bdb.collection.createTextIndex({ content: 1 })
Cdb.collection.createIndex({ content: "text" })
Ddb.collection.createText({ content: "text" })
What operator do you use to search text indexed fields in MongoDB?
A$search
B$indexText
C$findText
D$text
Can a MongoDB collection have only one text index?
AYes, only one text index per collection is allowed
BNo, multiple text indexes are allowed
CYes, but only if fields are different
DNo, text indexes are unlimited
What does the $language option do in a text search query?
ASets the language for stemming and stop words in search
BSpecifies the language for sorting results
CFilters documents by language field
DChanges the database language
Which of these queries searches for documents containing the word 'apple' in text indexed fields?
A{ text: "apple" }
B{ $text: { $search: "apple" } }
C{ $search: "apple" }
D{ $find: "apple" }
Explain how to create and use a text index in MongoDB for searching text fields.
Think about how to prepare the collection and then how to search.
You got /4 concepts.
    Describe the role of the $language option in MongoDB text search and why it matters.
    Consider how language rules affect word matching.
    You got /3 concepts.