Complete the code to create a search index named 'myIndex' on the 'products' collection.
db.products.createIndex({ [1]: "text" }, { name: "myIndex" })The 'name' field is commonly indexed for text search in Atlas Search. This command creates a text index on the 'name' field.
Complete the code to perform a text search for the word 'coffee' using the '$search' stage in an aggregation pipeline.
db.products.aggregate([{ $search: { text: { query: [1], path: "name" } } }])The query value must be the string 'coffee' to search for that word in the 'name' field.
Fix the error in the aggregation pipeline to correctly search for 'espresso' in the 'description' field.
db.products.aggregate([{ $search: { text: { query: [1], path: "description" } } }])The query value must be a string literal, so it needs to be enclosed in double quotes.
Fill both blanks to create a compound search index on 'name' and 'category' fields.
db.products.createIndex({ [1]: "text", [2]: "text" })Compound text indexes can include multiple fields like 'name' and 'category' to improve search coverage.
Fill all three blanks to perform a search for 'latte' in the 'name' field, sort results by 'price' ascending, and limit to 5 results.
db.products.aggregate([{ $search: { text: { query: [1], path: [2] } } }, { $sort: { [3]: 1 } }, { $limit: 5 }])The query searches for 'latte' in the 'name' field, sorts by 'price' ascending (1), and limits results to 5.