Intermediate MongoDB test (Intermediate)
30 questions · 35 minutes · Free
Aggregation pipelines, index design, data modelling and replica sets.
Take the Intermediate MongoDB test
What it covers
- Aggregation pipeline
- Compound and text indexes
- Embedding vs referencing
- Multi-document transactions
- Replica sets
Interview format
- Questions: 30 questions — 18 multiple choice, 9 multi-answer, 3 predict-the-output
- Time: 35 minutes, timed from the first question
- Difficulty: Intermediate
- Skill area: Data
- Price: Free
Earn a certificate
The Intermediate MongoDB test is one of the 6 tests of the Full-Stack Developer (MERN): Intermediate learning path. Pass it and the other 5 tests at 70% or more and readyforhires issues you a verifiable certificate in your name, with its own code and verify link to share or add to LinkedIn.
Sample questions
5 sample questions from the Intermediate MongoDB test, with the answers. Samples are taken out of the live test, so you will not meet these when you sit it.
Which of the following statements correctly describes how a compound index can improve query performance for a specific use case?
- A single-field index on {age: -1} would improve the performance of queries filtering by name and sorting by age in descending order.
- A compound index on {age: 1, name: -1} would improve the performance of queries filtering by name and sorting by age in descending order.
- A compound index on {name: 1, age: -1} would improve the performance of queries filtering by name and sorting by age in descending order.
- A single-field index on {name: 1} would improve the performance of queries filtering by name and sorting by age in descending order.
Answer: C. A compound index on {name: 1, age: -1} would improve the performance of queries filtering by name and sorting by age in descending order.
A compound index that includes both the fields used in the query filter and the sort operation can significantly enhance query performance. In this case, the index {name: 1, age: -1} allows the database to efficiently filter documents by name and sort them by age in descending order without requiring additional sorting steps. Other options may not align with how compound indexes are used for filtering and sorting.
Which of the following statements correctly describes the purpose and behavior of the $match stage in an aggregation pipeline?
- The $match stage is applied after all other stages in the aggregation pipeline.
- The $match stage is used to group documents based on a specified field.
- The $match stage can only be used in the final stage of an aggregation pipeline.
- The $match stage filters documents before they are processed by subsequent stages, improving performance by reducing the number of documents passed along the pipeline.
Answer: D. The $match stage filters documents before they are processed by subsequent stages, improving performance by reducing the number of documents passed along the pipeline.
The $match stage is used to filter documents early in the aggregation pipeline, which can significantly improve performance by reducing the dataset size before further processing. The other options either describe incorrect behaviors or are not directly related to the purpose of the $match stage.
Which of the following statements correctly describes the purpose of compound indexes in MongoDB?
- Compound indexes do not affect query performance.
- Compound indexes are automatically created for every query.
- Compound indexes are only useful for single-field queries.
- Compound indexes improve query performance for queries that filter on multiple fields.
Answer: D. Compound indexes improve query performance for queries that filter on multiple fields.
A compound index is created on multiple fields and can significantly improve query performance for queries that filter on those fields. Other options may be misleading or incorrect based on the actual behavior of compound indexes in MongoDB.
A developer is working on a project that requires joining the 'orders' collection with the 'customers' collection in an aggregation pipeline. Which of the following is the correct usage of the $lookup stage for this purpose?
- Use the $lookup stage to calculate the average order value for each customer.
- Use the $lookup stage to sort the 'orders' collection by total amount in descending order.
- Use the $lookup stage to filter documents in the 'orders' collection based on a specific date range.
- Use the $lookup stage to join the 'orders' collection with the 'customers' collection based on customer ID.
Answer: D. Use the $lookup stage to join the 'orders' collection with the 'customers' collection based on customer ID.
The $lookup stage is used in MongoDB aggregation pipelines to perform left outer joins between collections. In this scenario, joining the 'orders' and 'customers' collections based on the customer ID is the correct use of the $lookup stage. The other options either describe incorrect usage or are unrelated to the functionality of the $lookup stage.
Which of the following accurately describes the role of write concern in transactions when applied in a realistic project scenario?
- Write concern in transactions is only relevant for single-document operations.
- Write concern in transactions is not supported in MongoDB versions prior to 4.0.
- Write concern in transactions is automatically set to 'majority' in all cases.
- Write concern in transactions ensures that data is written to a majority of nodes in a replica set before the transaction is considered successful.
Answer: D. Write concern in transactions ensures that data is written to a majority of nodes in a replica set before the transaction is considered successful.
Write concern in transactions is crucial for ensuring data durability and consistency in MongoDB. By setting a write concern of 'majority', the transaction guarantees that the data is written to a majority of nodes in the replica set before the transaction is committed. This provides strong consistency and fault tolerance, which is essential in a realistic project scenario where data integrity is a priority. Other options may describe unrelated or incorrect concepts.
Frequently asked questions
- How many questions are in the Intermediate MongoDB test?
- 30 questions (18 multiple choice, 9 multi-answer, 3 predict-the-output), with 35 minutes to answer them.
- What does the Intermediate MongoDB test cover?
- Aggregation pipeline, Compound and text indexes, Embedding vs referencing, Multi-document transactions, Replica sets.
- Is the Intermediate MongoDB test free?
- Yes. It is free to take with a readyforhires account.
- What level is the Intermediate MongoDB test?
- Intermediate, in Data.