0
0
MongoDBquery~20 mins

Atlas search overview in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Atlas Search Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Find documents matching a text phrase using Atlas Search
Given a collection named books with an Atlas Search index on the title field, what is the output of this query?
MongoDB
db.books.aggregate([
  {
    $search: {
      text: {
        query: "adventure",
        path: "title"
      }
    }
  },
  { $project: { title: 1, _id: 0 } }
])
A[{ "title": "The Great Adventure" }, { "title": "Adventure in the Mountains" }]
B[{ "title": "The Great Adventure" }, { "title": "Cooking Recipes" }]
C[{ "title": "Cooking Recipes" }, { "title": "Gardening Tips" }]
D[]
Attempts:
2 left
💡 Hint
Think about which titles contain the word 'adventure'.
🧠 Conceptual
intermediate
1:30remaining
Understanding Atlas Search index types
Which of the following best describes the purpose of an Atlas Search index in MongoDB?
AIt automatically encrypts data at rest in the database.
BIt stores backup copies of the database for disaster recovery.
CIt enables fast, full-text search queries on specified fields using Lucene technology.
DIt manages user authentication and access control.
Attempts:
2 left
💡 Hint
Atlas Search uses a popular open-source search engine technology.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in this Atlas Search query
What error does this query raise?
MongoDB
db.products.aggregate([
  {
    $search: {
      text: {
        query: "smartphone",
        path: ["name", "description"]
      }
    }
  }
])
ASyntaxError: The 'path' field must be a string, not an array.
BRuntimeError: The $search stage is not supported in aggregate pipelines.
CTypeError: The 'query' field must be an array of strings.
DNo error; the query runs successfully and returns matching documents.
Attempts:
2 left
💡 Hint
Check the Atlas Search documentation for the 'text' operator's 'path' field type.
optimization
advanced
2:30remaining
Improve performance of an Atlas Search query filtering by category
You want to find documents with 'laptop' in the 'title' and category 'electronics'. Which query is more efficient?
AUse $search with compound operator combining text on 'title' and equals on 'category'.
BUse $match on 'category' first, then $search with text operator on 'title'.
CUse $search with text operator on 'title' and then $match on 'category' after $search.
DUse $match on both 'title' and 'category' without $search.
Attempts:
2 left
💡 Hint
Atlas Search compound operator can combine multiple conditions efficiently.
🔧 Debug
expert
3:00remaining
Why does this Atlas Search query return no results?
Given this query, why might it return an empty result set?
MongoDB
db.orders.aggregate([
  {
    $search: {
      text: {
        query: "urgent",
        path: "status"
      }
    }
  }
])
AThe query syntax is invalid because 'query' must be an array, not a string.
BThe 'status' field is not included in the Atlas Search index, so no matches are found.
CThe $search stage cannot be used on fields with string values.
DThe collection 'orders' does not exist, causing the query to return no results.
Attempts:
2 left
💡 Hint
Check if the field you search is indexed by Atlas Search.