MEAN Stack Development MCQ 3 — Questions and Answers
Question 1: Which of the following correctly describes a MongoDB 'replica set'?
- A horizontal sharding configuration for distributing data
- A group of mongod instances maintaining the same dataset for redundancy (Correct answer)
- A collection of indexes on a single document field
- A backup strategy using scheduled snapshots
Correct answer: A group of mongod instances maintaining the same dataset for redundancy
A replica set is a group of MongoDB servers that maintain the same data, providing redundancy and high availability through automatic failover.
Question 2: In Angular, what is a `Resolver` used for in routing?
- To guard routes from unauthorized access
- To pre-fetch data before a route is activated (Correct answer)
- To lazy-load feature modules on demand
- To define URL parameter patterns for a route
Correct answer: To pre-fetch data before a route is activated
A Resolver pre-fetches data before the route is activated, ensuring the component has all required data when it initializes.
Question 3: What is the default behavior of Node.js's `EventEmitter` when an 'error' event is emitted with no listener?
- The error is silently ignored
- A warning is logged to console
- An exception is thrown and the process may crash (Correct answer)
- The error is queued until a listener is added
Correct answer: An exception is thrown and the process may crash
If no listener handles the 'error' event on an EventEmitter, Node.js throws the error as an exception, potentially crashing the process.
Question 4: Which Express.js method is used to serve static files from a directory?
- express.static() (Correct answer)
- express.public()
- app.serve()
- app.files()
Correct answer: express.static()
express.static() is a built-in middleware that serves static assets like HTML, CSS, and images from a specified directory.
Question 5: What does the MongoDB `$lookup` aggregation stage perform?
- Searches for a text string across all collections
- Performs a left outer join with another collection (Correct answer)
- Looks up an index for optimizing a query
- Finds documents matching a specific field value
Correct answer: Performs a left outer join with another collection
$lookup performs a left outer join to another collection in the same database, adding matched documents as an array field.
Question 6: In Angular, which lifecycle hook is called after every change detection cycle for a component's content projections?
- ngAfterViewChecked
- ngAfterContentChecked (Correct answer)
- ngDoCheck
- ngOnChanges
Correct answer: ngAfterContentChecked
ngAfterContentChecked is called after Angular checks the content projected into the component during every change detection cycle.
Question 7: What is the purpose of `process.env.NODE_ENV` in a Node.js application?
- To set the Node.js version for the runtime
- To indicate the runtime environment (development, production, test) (Correct answer)
- To configure the number of worker threads
- To specify the entry point file for the application
Correct answer: To indicate the runtime environment (development, production, test)
NODE_ENV is a convention-based environment variable that indicates the environment context, enabling conditional behavior in code and libraries.
Which of the following correctly describes a MongoDB 'replica set'?