MEAN Stack Development MCQ 2 — Questions and Answers
Question 1: Which MongoDB operator is used to update a field only if the new value is greater than the current value?
- $set
- $max (Correct answer)
- $inc
- $push
Correct answer: $max
The $max operator updates the field only when the specified value is greater than the existing field value.
Question 2: In Express.js, what does the `next()` function do when called with an error argument like `next(err)`?
- Skips to the next route handler
- Invokes the next error-handling middleware (Correct answer)
- Terminates the request-response cycle
- Redirects to a 500 error page
Correct answer: Invokes the next error-handling middleware
Calling next(err) skips all remaining non-error middleware and passes control to the next error-handling middleware (which has four parameters: err, req, res, next).
Question 3: In Angular, what is the purpose of the `ChangeDetectionStrategy.OnPush` setting?
- Forces change detection on every browser event
- Limits change detection to when input references change or events are emitted (Correct answer)
- Disables change detection entirely for the component
- Runs change detection only on component initialization
Correct answer: Limits change detection to when input references change or events are emitted
OnPush strategy tells Angular to run change detection only when input properties change by reference or an observable emits, improving performance.
Question 4: What does `npm ci` do differently compared to `npm install`?
- Installs only production dependencies
- Installs from package-lock.json exactly, deleting node_modules first (Correct answer)
- Checks for security vulnerabilities before installing
- Updates all packages to their latest versions
Correct answer: Installs from package-lock.json exactly, deleting node_modules first
npm ci removes node_modules and installs dependencies exactly as specified in package-lock.json, ensuring reproducible builds.
Question 5: Which Node.js module is used to work with file and directory paths in a cross-platform way?
- fs
- os
- path (Correct answer)
- url
Correct answer: path
The path module provides utilities for working with file and directory paths, handling differences between POSIX and Windows systems automatically.
Question 6: In MongoDB aggregation, which stage is used to reshape documents by adding, removing, or computing new fields?
- $match
- $group
- $project (Correct answer)
- $sort
Correct answer: $project
The $project stage reshapes each document in the stream, allowing you to include, exclude, or add computed fields.
Question 7: What Angular decorator is used to inject a service into a component's constructor?
- @Injectable
- @Component
- @Inject (Correct answer)
- @NgModule
Correct answer: @Inject
The @Inject decorator explicitly specifies a dependency token when constructor parameter type alone is insufficient for Angular's DI system.
Which MongoDB operator is used to update a field only if the new value is greater than the current value?