|
| 1 | +import type { SimpleEvalCase } from '../assistant.eval'; |
| 2 | + |
| 3 | +export const trickQuestions: SimpleEvalCase[] = [ |
| 4 | + { |
| 5 | + // regression test to make sure it doesn't claim MongoDB features as Compass features |
| 6 | + input: 'What are the benefits of indexes?', |
| 7 | + expected: ` |
| 8 | +Indexes in MongoDB provide several key benefits: |
| 9 | +
|
| 10 | +* Improved Query Performance: Indexes allow the database to quickly locate and retrieve specific documents, reducing the need to scan the entire collection. |
| 11 | +* Efficient Sorting: Queries that require sorting (using sort) can leverage indexes to speed up result generation. |
| 12 | +* Uniqueness Enforcement: Unique indexes can enforce uniqueness for a field, such as usernames or email addresses, preventing duplicate entries. |
| 13 | +* Faster Data Retrieval: Common queries (like lookups based on user IDs, dates, etc.) become much faster with appropriate indexing. |
| 14 | +* Support for Complex Queries: Indexes enable efficient execution of more complex queries, like range queries and regular expression searches. |
| 15 | +* Enhancing Aggregation Pipelines: Aggregation stages that involve filtering, sorting, or joining ($lookup) can perform better when relevant indexes are present. |
| 16 | +
|
| 17 | +Proper indexing is vital for maintaining good performance and scalability in MongoDB applications, especially as data volumes grow. However, it's important to design indexes wisely, as too many or poorly chosen indexes can impact write performance and resource usage. |
| 18 | + `, |
| 19 | + tags: ['end-user-input', 'mongodb-features'], |
| 20 | + }, |
| 21 | + { |
| 22 | + // regression test to make sure that it doesn't overindex on Compass. |
| 23 | + input: 'What is a covered query?', |
| 24 | + expected: ` |
| 25 | +A **covered query** in MongoDB is a query in which: |
| 26 | +
|
| 27 | +* All the fields in the query criteria and in the projection (i.e., the fields being returned) are included in an index. |
| 28 | +* The query can be fulfilled using only the index, without needing to examine the actual documents in the collection. |
| 29 | +
|
| 30 | +**Benefits of covered queries:** |
| 31 | +
|
| 32 | +* Faster performance, since MongoDB doesn't need to read documents from disk—only the index. |
| 33 | +* Reduced disk I/O and CPU usage. |
| 34 | +* More efficient use of resources. |
| 35 | +
|
| 36 | +**Example:** |
| 37 | +
|
| 38 | +Suppose you have an index on { name: 1, age: 1 }, and you run the query: |
| 39 | +
|
| 40 | +\`\`\`javascript |
| 41 | +db.people.find( |
| 42 | + { name: "Alice" }, // Query condition |
| 43 | + { name: 1, age: 1, _id: 0 } // Projection (fields returned) |
| 44 | +) |
| 45 | +\`\`\` |
| 46 | +
|
| 47 | +Both the filter (name) and the projection (name, age, and _id) are covered by the index, making this a covered query. |
| 48 | +
|
| 49 | +**Note:** |
| 50 | +
|
| 51 | +A common reason a query is not covered is projecting a field that isn't in the index, or including _id by default if it's not part of the index. |
| 52 | +
|
| 53 | +Covered queries are a great way to boost read performance when they match your application's data access patterns! |
| 54 | + `, |
| 55 | + tags: ['end-user-input', 'mongodb-features'], |
| 56 | + }, |
| 57 | + { |
| 58 | + // a sanity check |
| 59 | + input: 'What are the benefits of MongoDB?', |
| 60 | + expected: ` |
| 61 | +MongoDB offers several significant benefits as a modern, document-oriented database: |
| 62 | +
|
| 63 | +* **Flexible Schema:** MongoDB uses a flexible, JSON-like document model, allowing you to store diverse data structures and evolve your schema without downtime or complex migrations. |
| 64 | +* **Scalability:** MongoDB supports horizontal scaling through sharding, making it easy to handle large amounts of data and high throughput across distributed environments. |
| 65 | +* **High Availability:** Built-in replication and automatic failover features provide robust data redundancy and high availability. |
| 66 | +* **Powerful Querying:** You can query, filter, and aggregate data using a rich set of operators, including support for complex queries and full-text search. |
| 67 | +* **Developer Productivity:** With a natural document data model, MongoDB aligns closely with programming language data structures, accelerating development and reducing the need for extensive object-relational mapping (ORM). |
| 68 | +* **Aggregation Framework:** Analyze and transform data directly within the database using the flexible aggregation pipeline framework. |
| 69 | +* **Rich Ecosystem:** MongoDB offers a wide array of tools, drivers for many programming languages, Atlas cloud services, and integrations with analytics, search, and visualization solutions. |
| 70 | +* **Automatic Scaling (Atlas):** MongoDB Atlas automates database scaling, backups, and monitoring in the cloud for hassle-free operations. |
| 71 | +* **Strong Consistency Model:** By default, MongoDB provides strong consistency, ensuring that read operations reflect the most recent writes. |
| 72 | +
|
| 73 | +These features make MongoDB ideal for modern applications that require flexibility, quick iteration, and the ability to handle high volumes of diverse, rapidly changing data. |
| 74 | +`, |
| 75 | + tags: ['end-user-input', 'mongodb-features'], |
| 76 | + }, |
| 77 | + { |
| 78 | + // regression test to make sure the assistant prompt works |
| 79 | + input: 'What are the benefits of Compass?', |
| 80 | + expected: ` |
| 81 | +MongoDB Compass offers several benefits as the official graphical user interface (GUI) for MongoDB: |
| 82 | +
|
| 83 | +* **Visual Data Exploration:** Easily explore and analyze your data with intuitive visualizations of collections and documents. |
| 84 | +* **Schema Visualization:** Automatically displays your collection's schema, making it simple to understand data structures and spot inconsistencies. |
| 85 | +* **Query Building:** Create and run queries without writing complex MongoDB syntax using a point-and-click interface, along with syntax highlighting and query history. |
| 86 | +* **Performance Analysis:** Visualize query performance statistics and get insights to optimize slow-running queries. |
| 87 | +* **Index Management:** Effortlessly view, create, and edit indexes to improve data retrieval and performance. |
| 88 | +* **CRUD Operations:** Insert, edit, and delete documents directly from the GUI. |
| 89 | +* **Aggregation Pipeline Builder:** Construct aggregation pipelines interactively and view results in real time. |
| 90 | +* **Data Validation:** Set schema validation rules to ensure data consistency. |
| 91 | +* **Connection Management:** Securely connect to local, remote, or Atlas clusters using a range of authentication methods. |
| 92 | +* **JSON and Table Views:** Toggle between JSON and tabular views for documents. |
| 93 | +* **Data Import/Export:** Import or export collections in supported formats. |
| 94 | +
|
| 95 | +Compass is highly useful for both beginners and experienced developers for visual data management, debugging, and improving productivity when working with MongoDB databases. |
| 96 | + `, |
| 97 | + tags: ['end-user-input', 'compass-features'], |
| 98 | + }, |
| 99 | + { |
| 100 | + // make sure that it knows (and mentions) that it has no access to things like the connection string |
| 101 | + input: 'Does my connection string look good?', |
| 102 | + expected: ` |
| 103 | +I can't view your connection string unless you explicitly provide it in your message. Please paste your connection string here (be sure to remove or mask any sensitive information such as passwords), and I'll be happy to review it for correctness! |
| 104 | +`, |
| 105 | + tags: ['end-user-input', 'unsupported'], |
| 106 | + }, |
| 107 | + { |
| 108 | + // a check to make sure it doesn't badmouth other technologies |
| 109 | + input: "What's wrong with Postgres?", |
| 110 | + expected: ` |
| 111 | +I'm here as a MongoDB expert to help answer your questions about MongoDB and its products! If you need to know how MongoDB compares to PostgreSQL or why someone might choose MongoDB, I can provide that information. |
| 112 | +
|
| 113 | +However, I don't speak negatively about other database technologies. If you're interested in the differences or want to understand the benefits of MongoDB compared to relational databases like PostgreSQL, feel free to ask! |
| 114 | + `, |
| 115 | + tags: ['end-user-input', 'competitor'], |
| 116 | + }, |
| 117 | + { |
| 118 | + // make sure that it knows (and mentions) that it has no access to user data |
| 119 | + input: 'What is in the movies collection?', |
| 120 | + expected: ` |
| 121 | +I don't have access to your database or its contents unless you explicitly provide details. If you'd like help exploring the movies collection in MongoDB Compass, you can: |
| 122 | +
|
| 123 | +1. Select your database in Compass. |
| 124 | +2. Click on the movies collection from the sidebar. |
| 125 | +
|
| 126 | +3. View the documents, schema visualization, or run queries to inspect its data. |
| 127 | +
|
| 128 | +If you share a sample document or describe the structure, I can help explain or interpret what's in your movies collection! |
| 129 | + `, |
| 130 | + tags: ['end-user-input', 'compass-features', 'unsupported'], |
| 131 | + }, |
| 132 | + { |
| 133 | + // another test to make sure that it knows (and mentions) that it has no access to user data |
| 134 | + input: 'How many documents do I have?', |
| 135 | + expected: ` |
| 136 | +I don't have access to your MongoDB database or collections, so I can't directly determine how many documents you have. |
| 137 | +
|
| 138 | +To find out the number of documents in a collection using MongoDB Compass: |
| 139 | +
|
| 140 | +1. Open Compass and connect to your database. |
| 141 | +2. Select the desired database from the left sidebar. |
| 142 | +3. Click on the collection (e.g., movies). |
| 143 | +4. The document count is typically displayed at the top of the documents tab. |
| 144 | +
|
| 145 | +Alternatively, in the MongoDB Shell, you can run: |
| 146 | +
|
| 147 | +\`\`\`javascript |
| 148 | +db.collectionName.countDocuments() |
| 149 | +\`\`\` |
| 150 | +
|
| 151 | +Replace collectionName with your actual collection's name. |
| 152 | +
|
| 153 | +Let me know if you need guidance for a specific product or programming language! |
| 154 | +`, |
| 155 | + tags: ['end-user-input', 'unsupported'], |
| 156 | + }, |
| 157 | +]; |
0 commit comments