0
0
MongoDBquery~10 mins

Atlas search overview 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 search index named 'myIndex' on the 'products' collection.

MongoDB
db.products.createIndex({ [1]: "text" }, { name: "myIndex" })
Drag options to blanks, or click blank then click option'
Adescription
Bname
Cprice
Dcategory
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a numeric field like 'price' for a text index causes errors.
Using a field not present in the collection.
2fill in blank
medium

Complete the code to perform a text search for the word 'coffee' using the '$search' stage in an aggregation pipeline.

MongoDB
db.products.aggregate([{ $search: { text: { query: [1], path: "name" } } }])
Drag options to blanks, or click blank then click option'
A"coffee"
B"tea"
C"milk"
D"juice"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the search term.
Using a different word than 'coffee' which changes the search.
3fill in blank
hard

Fix the error in the aggregation pipeline to correctly search for 'espresso' in the 'description' field.

MongoDB
db.products.aggregate([{ $search: { text: { query: [1], path: "description" } } }])
Drag options to blanks, or click blank then click option'
A"espresso"
Bespresso
C'espresso'
Despresso"
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted words causes syntax errors.
Using mismatched quotes causes errors.
4fill in blank
hard

Fill both blanks to create a compound search index on 'name' and 'category' fields.

MongoDB
db.products.createIndex({ [1]: "text", [2]: "text" })
Drag options to blanks, or click blank then click option'
Aname
Bprice
Ccategory
Ddescription
Attempts:
3 left
💡 Hint
Common Mistakes
Including numeric fields like 'price' in a text index causes errors.
Using the same field twice.
5fill in blank
hard

Fill all three blanks to perform a search for 'latte' in the 'name' field, sort results by 'price' ascending, and limit to 5 results.

MongoDB
db.products.aggregate([{ $search: { text: { query: [1], path: [2] } } }, { $sort: { [3]: 1 } }, { $limit: 5 }])
Drag options to blanks, or click blank then click option'
A"latte"
B"name"
Cprice
Dcategory
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the query or path strings.
Sorting by a field not in the collection.
Using -1 instead of 1 for ascending sort.