MEAN Stack Development MCQ 5 — Questions and Answers
Question 1: Which MongoDB index type is most efficient for supporting queries that sort by multiple fields in a specific order?
- Single field index
- Compound index (Correct answer)
- Text index
- Hashed index
Correct answer: Compound index
A compound index on multiple fields supports queries that filter or sort by those fields in the indexed order, making it far more efficient than multiple single-field indexes.
Question 2: What is the key difference between Angular's `@ViewChild` and `@ContentChild` decorators?
- @ViewChild accesses template elements, @ContentChild accesses projected content (Correct answer)
- @ViewChild is for services, @ContentChild is for DOM elements
- @ViewChild works in constructor, @ContentChild works in ngOnInit
- @ViewChild is deprecated in favor of @ContentChild
Correct answer: @ViewChild accesses template elements, @ContentChild accesses projected content
@ViewChild queries elements within the component's own template, while @ContentChild queries elements that are projected into the component via ng-content.
Question 3: In Node.js, what does the `cluster` module allow you to do?
- Connect to a MongoDB cluster automatically
- Create child processes that share server ports to utilize multiple CPU cores (Correct answer)
- Manage multiple npm packages as a single unit
- Group related event listeners for batch removal
Correct answer: Create child processes that share server ports to utilize multiple CPU cores
The cluster module lets you create worker processes that all share the same server port, enabling a Node.js app to take advantage of multi-core systems.
Question 4: What does the Express.js `app.use()` method do when no path is specified as the first argument?
- It applies the middleware only to the root '/' route
- It applies the middleware to every incoming request regardless of path (Correct answer)
- It throws an error because path is required
- It applies middleware only to GET requests
Correct answer: It applies the middleware to every incoming request regardless of path
When no path is specified, app.use() mounts middleware that executes for every request, regardless of the URL path or HTTP method.
Question 5: Which Angular feature allows you to define template variables that reference DOM elements or component instances within a template?
- Property binding
- Template reference variables (Correct answer)
- Structural directives
- Component outputs
Correct answer: Template reference variables
Template reference variables (declared with #varName) give you a reference to a DOM element or component instance that you can use elsewhere in the same template.
Question 6: What is the purpose of MongoDB's `writeConcern` option in write operations?
- It controls which fields are written to disk during an update
- It specifies the level of acknowledgment required from MongoDB before a write is considered successful (Correct answer)
- It sets the maximum document size for write operations
- It determines the order in which bulk write operations are executed
Correct answer: It specifies the level of acknowledgment required from MongoDB before a write is considered successful
writeConcern specifies the level of acknowledgment MongoDB must receive before returning success, balancing between performance (w:0) and durability (w:'majority').
Question 7: In the context of the MEAN stack, what role does JWT (JSON Web Token) most commonly play?
- It encrypts MongoDB documents for storage security
- It provides stateless authentication between Angular clients and Node/Express APIs (Correct answer)
- It compresses HTTP responses between Express and Angular
- It caches frequently accessed MongoDB queries
Correct answer: It provides stateless authentication between Angular clients and Node/Express APIs
JWT is used for stateless authentication: the Angular client stores a signed token after login and sends it in headers with each API request, which Express verifies without needing session storage.
Which MongoDB index type is most efficient for supporting queries that sort by multiple fields in a specific order?