0% found this document useful (0 votes)
90 views

MERN Interview Questions by Shilpi

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

MERN Interview Questions by Shilpi

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

React JS Interview Questions

1. What is React.js and what problem does it solve?


React.js is a JavaScript library developed by Facebook for building user interfaces. It solves the
problem of efficiently updating the user interface in web applications. By using a virtual DOM
and a declarative programming approach, React allows developers to create interactive UIs
that can efficiently render and update components in response to data changes.

2. What are the key features of React.js?


Some key features of React.js include:
- Virtual DOM for efficient rendering and updating of components.
- Component-based architecture for building reusable and maintainable UIs.
- Declarative syntax using JSX for describing UI components.
- One-way data flow with unidirectional data binding for predictable application state
management.
- Support for server-side rendering for improved performance and SEO.

3. Explain the concept of Virtual DOM in React.js and its significance.


The Virtual DOM in React.js is a lightweight, in-memory representation of the actual DOM. It
acts as a layer between the components and the browser's DOM, allowing React to perform
efficient updates to the UI. When the state of a component changes, React constructs a new
Virtual DOM tree, compares it with the previous one, and computes the minimal set of changes
needed to update the actual DOM. This approach significantly improves performance by
minimizing DOM manipulation operations.

4. What is JSX in React.js? How does it differ from HTML?


JSX (JavaScript XML) is a syntax extension in React.js that allows developers to write HTML-like
code directly within JavaScript. JSX is similar to HTML but has some key differences:
- JSX allows embedding JavaScript expressions within curly braces `{}`.
- JSX attributes use camelCase naming convention instead of HTML's kebab-case.
- JSX supports embedding JavaScript logic and variables directly within the markup.

5. How does React handle components? Explain the component lifecycle methods.
React manages components as self-contained units that encapsulate UI and behavior.
Components have a lifecycle consisting of various stages:
- Mounting: When a component is created and inserted into the DOM.
- Updating: When a component's state or props change, triggering a re-render.

Sheet Prepared By CrazyWebDev Academy


- Unmounting: When a component is removed from the DOM.
React provides lifecycle methods like `componentDidMount`, `componentDidUpdate`, and
`componentWillUnmount` to hook into these stages and perform actions such as initialization,
data fetching, or cleanup.

6. What is state in React.js? How is it different from props?


State in React.js represents the internal data of a component that can change over time. It is
managed by the component itself using the `useState` hook or the `setState` method in class
components. Props, on the other hand, are immutable data passed from a parent component
to its children. While state is managed internally and can be changed by the component itself,
props are read-only and cannot be modified by the component.

7. What are controlled and uncontrolled components in React.js? When would you use each?
Controlled components are React components whose value is controlled by React state.
Changes to the input value are handled by React through state updates. Uncontrolled
components, on the other hand, allow the input value to be controlled by the DOM itself. You
would typically use controlled components when you need to handle the input value
programmatically or validate user input. Uncontrolled components are useful for integrating
with third-party libraries or when you want to delegate the handling of input value to the DOM.

8. How do you pass data between components in React.js?


Data can be passed between components in React.js using props. Props are passed from
parent to child components and can be accessed within the child component using `this.props`
in class components or directly as arguments in functional components. For more complex
scenarios involving sibling components or deep nesting, you can use state management
libraries like Redux or context API.

9. What are keys in React and why are they important?


Keys are special attributes used by React to identify each child component uniquely when
rendering arrays of components. Keys help React identify which items have changed, are
added, or are removed efficiently during updates. Using keys correctly can improve the
performance and behavior of components, especially when rendering dynamic lists or
collections.

10. What is the purpose of the `setState()` method in React.js?


The `setState()` method in React.js is used to update the state of a component. It takes an
object or a function as an argument, representing the new state values or a function that

Sheet Prepared By CrazyWebDev Academy


returns the new state values based on the previous state. When `setState()` is called, React
schedules a re-render of the component and its children with the updated state values.

11. Explain the concept of conditional rendering in React.js.


Conditional rendering in React.js involves rendering different components or UI elements
based on certain conditions or logic. This can be achieved using JavaScript expressions within
JSX or by using conditional statements like `if` or ternary operators. Conditional rendering allows
developers to create dynamic UIs that adapt to different states or user interactions.

12. What are Higher Order Components (HOCs) in React.js? How do they work?
Higher Order Components (HOCs) are a design pattern in React.js for reusing component
logic. HOCs are functions that take a component as input and return a new component with
additional functionality. They enable cross-cutting concerns such as logging, authentication, or
code reuse to be encapsulated in separate components. HOCs enhance composability and
maintainability by promoting separation of concerns.

13. What is React Router? How do you implement routing in React.js applications?
React Router is a popular routing library for React.js applications that enables client-side
routing and navigation. It provides a declarative API for defining routes and rendering
components based on the current URL. To implement routing in React.js applications using
React Router, you would typically define route configurations using `<Route>` components,
handle navigation using `<Link>` or programmatic navigation, and use features like nested
routes, route parameters, and route guards for more complex routing scenarios.

14. What are Hooks in React.js? How do they differ from class components?
Hooks are a feature introduced in React.js version 16.8 that allow functional components to
use state and other React features without writing a class. Hooks provide a more concise and
functional programming-oriented way of managing component state, lifecycle, and side
effects. Unlike class components, which require extending from `React.Component` and using
lifecycle methods, functional components with hooks can encapsulate stateful logic and side
effects directly within the function body, promoting cleaner and more modular code.

15. Explain the differences between `useState`, `useEffect`, `useContext`, and `useReducer` hooks.
- `useState`: Hook for adding state to functional components.
- `useEffect`: Hook for performing side effects in functional components, such as data fetching
or DOM manipulation.
- `useContext`: Hook for consuming React context within functional components.

Sheet Prepared By CrazyWebDev Academy


- `useReducer`: Hook for managing complex state logic using a reducer function, similar to
Redux.

16. How do you handle forms in React.js? Explain controlled and uncontrolled form components.
In React.js, forms can be handled using controlled or uncontrolled components. Controlled
components bind form inputs to React state, allowing React to control and validate
input values. This is done by setting the value attribute of the form inputs to state variables and
providing event handlers to update the state when the input values change. Controlled
components provide a single source of truth for form data, making it easier to manage and
validate input values.

On the other hand, uncontrolled components allow the DOM to control the form inputs. Instead
of managing input values through state, you let the DOM handle them directly. Uncontrolled
components are useful for integrating with third-party libraries or when you want to optimize
performance by avoiding unnecessary re-renders.

17. What are the differences between functional components and class components in React.js?
- Functional components: These are simple JavaScript functions that accept props as input
and return React elements to describe the UI. With the introduction of hooks, functional
components can also manage state and have access to lifecycle methods.
- Class components: These are ES6 classes that extend `React.Component` and have their
own internal state and lifecycle methods. Class components were the traditional way of
creating React components before the introduction of hooks.

18. How do you optimize performance in React.js applications?


Performance optimization in React.js applications can be achieved through various
techniques such as:
- Memoization: Memoizing expensive computations or rendering using libraries like `memo` or
`useMemo`.
- Code splitting: Splitting the application code into smaller chunks and loading them
asynchronously using tools like Webpack or React.lazy.
- Virtualization: Rendering large lists efficiently using virtualization libraries like
react-virtualized or react-window.
- Minimizing re-renders: Avoiding unnecessary re-renders by using `React.memo`, optimizing
state updates, and using shouldComponentUpdate lifecycle method in class components.
- Optimizing network requests: Caching data, prefetching resources, and minimizing the
number of network requests can improve performance.

Sheet Prepared By CrazyWebDev Academy


19. What are React Fragments and when would you use them?
React Fragments are a way to group multiple children elements without adding extra nodes
to the DOM. They provide a cleaner syntax for rendering adjacent JSX elements that don't need
a parent container. You would use React Fragments when you want to return multiple elements
from a component without adding a wrapper `<div>` or any other unnecessary DOM element.

20. How do you handle events in React.js?


In React.js, you handle events using event handlers, which are functions that are called in
response to user interactions. Event handlers are typically passed as props to child
components or attached directly to DOM elements using JSX syntax. Common event handlers
in React include `onClick`, `onChange`, `onSubmit`, `onMouseOver`, etc. Event handlers receive
synthetic events as arguments, which wrap native browser events and provide cross-browser
compatibility and additional features.

Sheet Prepared By CrazyWebDev Academy


Redux Interview Questions
1. What is Redux and why is it used?
- Redux is a predictable state container for JavaScript applications, primarily used with React
for managing application state in a more organized and predictable way. It helps in managing
complex application states efficiently by providing a centralized store.

2. What are the core principles of Redux?


- The core principles of Redux include:
- Single source of truth: The state of your whole application is stored in an object tree within a
single store.
- State is read-only: The only way to change the state is by dispatching actions, which
describe what happened.
- Changes are made with pure functions: To specify how the state tree is transformed by
actions, you write pure reducers.

3. Explain the concept of a "store" in Redux.


- The store is the object that holds the application state and provides methods to interact
with it. It is the single source of truth in a Redux application. You can get the current state via
`getState()`, dispatch actions to change the state via `dispatch(action)`, and subscribe to
changes via `subscribe(listener)`.

4. What are the main components of Redux architecture?


- The main components of Redux architecture are:
- Store
- Actions
- Reducers
- Middleware (optional but often used)

5. Describe the role of actions in Redux.


- Actions are payloads of information that send data from your application to the Redux store.
They are plain JavaScript objects that must have a `type` property indicating the type of action
being performed. They are typically generated by action creator functions.

6. What are reducers and what purpose do they serve in Redux?

Sheet Prepared By CrazyWebDev Academy


- Reducers are pure functions that specify how the application's state changes in response to
actions sent to the store. They take the previous state and an action as arguments and return
the next state.

7. Explain the concept of immutability in Redux and why it's important.


- Immutability means that once an object is created, it cannot be changed. In Redux, it's
important to maintain immutability because it ensures predictability and helps in tracking
changes efficiently. It allows for easy detection of state changes and helps in optimizing
performance.

8. What is a Redux middleware? Provide examples of some popular middleware.


- Redux middleware provides a third-party extension point between dispatching an action
and the moment it reaches the reducer. Examples of popular middleware include `redux-thunk`
for handling asynchronous actions, `redux-logger` for logging actions and state changes, and
`redux-saga` for more complex asynchronous flow control.

9. Discuss the difference between mapStateToProps() and mapDispatchToProps().


- `mapStateToProps()` is a function used to subscribe to Redux store updates and get the
state as props in a React component. `mapDispatchToProps()` is a function used to dispatch
actions to the store as props in a React component.

10. What is the purpose of the connect() function in React-Redux?


- The `connect()` function is used to connect a React component to the Redux store. It
provides the component with the data it needs from the store, as well as the functions it can
use to dispatch actions to the store.

11. Explain the concept of "dispatching an action" in Redux.


- Dispatching an action means sending a type of action and optionally some payload data
to the Redux store. It is the way to trigger state changes in the Redux store.

12. How does Redux handle asynchronous operations?


- Redux itself does not handle asynchronous operations natively. However, middleware like
`redux-thunk` or `redux-saga` can be used to handle asynchronous actions. These middleware
allow actions to return functions instead of plain objects, enabling them to perform
asynchronous operations before dispatching the actual action.

13. What are the advantages of using Redux DevTools?

Sheet Prepared By CrazyWebDev Academy


- Redux DevTools provide a set of development tools for debugging Redux applications.
Advantages include the ability to track state changes over time, rewind and replay actions, and
inspect action payloads and state at each step. This can greatly simplify debugging and
understanding of application state.

14. Discuss the differences between Redux and Context API in React.
- Redux is a state management library primarily used for larger applications, providing a
centralized store, predictable state mutations, and middleware support. Context API is a feature
in React for sharing state between components without having to explicitly pass props down
through the component tree. While Context API can be used for state management, Redux
offers more features like time-travel debugging and middleware support.

15. How can you optimize performance in a Redux application?


- Performance optimization techniques in a Redux application include:
- Using `connect()`'s `shouldComponentUpdate` parameter to prevent unnecessary
re-renders.
- Using selectors to compute derived data.
- Normalizing state shape to avoid deeply nested structures.
- Using middleware like `redux-thunk` or `redux-saga` for asynchronous operations to keep
UI responsive.

16. What are some common anti-patterns to avoid when working with Redux?
- Common anti-patterns include:
- Mutating state directly in reducers.
- Using Redux for every piece of state in the application, even when it's not necessary.
- Overusing Redux middleware, which can complicate the codebase unnecessarily.
- Over-reliance on global state, which can lead to spaghetti code.

17. Explain the role of selectors in Redux applications.


- Selectors are functions that compute derived data from the Redux store. They are used to
encapsulate the logic for retrieving specific pieces of state in a Redux application. Selectors
help in keeping the state shape abstracted from the components and provide a centralized
place for accessing state.

18. Discuss the benefits of using Redux with TypeScript.


- Benefits of using Redux with TypeScript include:

Sheet Prepared By CrazyWebDev Academy


- Type safety: TypeScript provides static type checking, reducing the likelihood of runtime
errors related to state management.
- Enhanced development experience: TypeScript's IntelliSense provides auto-completion
and type hints, improving developer productivity.
- Better documentation: TypeScript interfaces and types can serve as documentation for the
shape of the state and actions in the Redux store.

19. What is the purpose of combineReducers() in Redux?


- `combineReducers()` is a utility function in Redux used to combine multiple reducers into a
single reducer function. It helps in managing different slices of state separately and keeps the
state tree well-organized.

20. Explain how you would handle complex nested state structures in Redux.
- To handle complex nested state structures, you can use techniques like normalizing the
state shape, breaking down the state into smaller manageable pieces, using selectors to
compute derived data, and organizing reducers hierarchically to mirror the nested state
structure.

Sheet Prepared By CrazyWebDev Academy


Node JS Interview Questions

1. What is Node.js, and how does it differ from traditional server-side languages?
- Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It allows developers
to run JavaScript code on the server-side, enabling non-blocking, event-driven architecture,
which differs from traditional server-side languages like PHP or Python that follow a blocking I/O
model.

2. How does Node.js handle asynchronous operations?


- Node.js uses event-driven, non-blocking I/O to handle asynchronous operations. It employs
callbacks, promises, and async/await to manage asynchronous code execution.

3. Explain the event-driven architecture of Node.js.


- In Node.js, everything is based on events. It utilizes an event loop that continuously listens for
events and executes associated callback functions when events occur. This architecture
enables handling multiple connections without blocking the execution of other code.

4. What is npm? How do you use it?


- npm (Node Package Manager) is a package manager for Node.js packages/modules. It
allows developers to install, manage, and share reusable JavaScript code. You can use npm to
install packages from the npm registry, manage dependencies, and publish your own
packages.

5. What is the purpose of package.json in a Node.js project?


- package.json is a metadata file in a Node.js project that contains project-specific
configuration information, such as project name, version, dependencies, scripts, etc. It also
specifies project dependencies, making it easy for other developers to install the necessary
dependencies.

6. How can you handle errors in Node.js?


- Errors in Node.js can be handled using try-catch blocks for synchronous code and by
attaching error handlers to promises or using the `.catch()` method. For asynchronous code,
error-first callbacks are commonly used, where the first parameter of the callback function is
reserved for an error object.

7. Explain the difference between callback functions, promises, and async/await in Node.js.

Sheet Prepared By CrazyWebDev Academy


- Callback functions are functions passed as arguments to be executed later. Promises are
objects representing the eventual completion or failure of an asynchronous operation, allowing
chaining and error handling. async/await is a syntactic sugar built on top of promises,
simplifying asynchronous code by allowing the use of synchronous-style code with the `async`
and `await` keywords.

8. What is middleware in the context of Node.js?


- Middleware in Node.js are functions that have access to the request, response objects, and
the next middleware function in the application’s request-response cycle. They can perform
tasks such as logging, authentication, error handling, etc.

9. How does Node.js manage memory?


- Node.js manages memory using V8's garbage collector, which automatically allocates and
deallocates memory for JavaScript objects. It employs techniques like generational garbage
collection to efficiently manage memory usage.

10. How can you debug a Node.js application?


- Node.js applications can be debugged using built-in debugging tools like `console.log()`
statements, or by using debugging features provided by IDEs (Integrated Development
Environments) such as breakpoints, watch variables, and step-through execution.

Sheet Prepared By CrazyWebDev Academy


Express.js Interview Questions

1. What is Express.js, and why is it used in Node.js applications?


- Express.js is a web application framework for Node.js, designed to build web applications
and APIs quickly and easily. It simplifies common tasks like routing, middleware handling, and
request handling.

2. How do you install and set up Express.js in a project?


- You can install Express.js using npm by running `npm install express`. After installation, you
can create an instance of Express and start defining routes and middleware for your
application.

3. Explain routing in Express.js.


- Routing in Express.js involves mapping HTTP methods and URL patterns to handler functions.
Routes are defined using methods like `app.get()`, `app.post()`, etc., specifying the URL pattern
and the corresponding handler function.

4. What are middleware functions in Express.js? Provide examples.


- Middleware functions in Express.js are functions that have access to the request, response
objects, and the next middleware function. They can perform tasks such as logging,
authentication, error handling, etc. Example: `app.use(loggerMiddleware)`.

5. How do you handle static files in Express.js?


- Static files (e.g., HTML, CSS, images) can be served in Express.js using the built-in
`express.static()` middleware. You specify the directory containing the static files, and Express
will serve them when requested.

6. What is templating in Express.js, and how do you use it?


- Templating in Express.js involves rendering dynamic content using template engines like EJS,
Pug (formerly Jade), Handlebars, etc. You set up a view engine in Express, specify the template
files, and pass data to be rendered to the templates.

7. Explain the role of the `req` and `res` objects in Express.js.


- The `req` (request) object represents the HTTP request and contains properties and methods
for accessing request data. The `res` (response) object represents the HTTP response and
contains methods for sending responses to the client.

Sheet Prepared By CrazyWebDev Academy


8. What is routing middleware? Provide an example.
- Routing middleware in Express.js is middleware that only applies to specific routes or groups
of routes. Example: `app.use('/api', apiRouter)` applies middleware to all routes starting with
'/api'.

9. How can you handle errors in Express.js?


- Errors in Express.js can be handled using error handling middleware, which is a special type
of middleware function that takes four arguments (err, req, res, next). You define error handling
middleware after all other middleware and route handlers.

10. How do you implement authentication and authorization in an Express.js application?


- Authentication and authorization can be implemented in Express.js using middleware
functions to validate user credentials and restrict access to certain routes or resources based
on user roles or permissions. Common techniques include using JSON Web Tokens (JWT),
session-based authentication, or OAuth.

Sheet Prepared By CrazyWebDev Academy


Backend Interview Questions

1. What is the difference between synchronous and asynchronous programming?


- Synchronous programming executes code sequentially, blocking further execution until the
current operation completes. Asynchronous programming allows multiple operations to be
executed concurrently, with results returned via callbacks, promises, or async/await.

2. What is RESTful architecture, and how does it relate to Node.js and Express.js?
- RESTful architecture is an architectural style for designing networked applications, typically
using HTTP protocols. It emphasizes stateless communication and resource-based URLs.
Node.js and Express.js are commonly used to implement RESTful APIs due to their flexibility and
ease of handling HTTP requests.

3. How do you handle file uploads in a Node.js/Express.js application?


- File uploads in Node.js/Express.js can be handled using middleware like `multer`, which
allows parsing multipart/form-data for file uploads. You specify the destination directory and
file size limits, and multer handles the file upload process.

4. What are sessions and cookies? How are they implemented in Express.js?
- Sessions and cookies are mechanisms for maintaining state between HTTP requests.
Sessions are typically stored server-side, while cookies are stored on the client-side. In
Express.js, sessions and cookies can be implemented using middleware like `express-session`
and `cookie-parser`. `express-session` manages user sessions by storing session data on the
server and associating a session ID with each client request, while `cookie-parser` parses
cookies sent by the client and populates `req.cookies` with the cookie data.

5. Explain the concept of clustering in Node.js.


- Clustering in Node.js involves spawning multiple instances of the Node.js process to take
advantage of multi-core systems and improve performance and scalability. The `cluster`
module in Node.js allows creating child processes (workers) that share server ports, enabling
load balancing and fault tolerance.

6. How do you deploy a Node.js/Express.js application?


- Node.js/Express.js applications can be deployed to various hosting platforms like Heroku,
AWS, DigitalOcean, etc. Typically, you package the application with its dependencies, configure

Sheet Prepared By CrazyWebDev Academy


environment variables, and deploy it to the hosting platform using tools like Git, Docker, or
deployment scripts.

7. What are streams in Node.js? How do they work?


- Streams in Node.js are objects that allow reading from or writing to a continuous flow of
data. They are implemented using EventEmitter and can be readable, writable, or both. Streams
enable efficient handling of large datasets by processing data in chunks, reducing memory
usage and improving performance.

8. How do you handle database operations in a Node.js/Express.js application?


- Database operations in Node.js/Express.js applications are typically handled using database
drivers or ORMs (Object-Relational Mappers). Common databases used with Node.js include
MongoDB, PostgreSQL, MySQL, and SQLite. You establish a connection to the database, execute
queries or operations, and handle results asynchronously.

9. What is CORS, and how do you enable it in Express.js?


- CORS (Cross-Origin Resource Sharing) is a security mechanism that allows web servers to
specify which origins have access to their resources. In Express.js, you can enable CORS by
using the `cors` middleware, which adds appropriate CORS headers to HTTP responses, allowing
cross-origin requests from specified origins.

10. Explain the concept of middleware chaining in Express.js.


- Middleware chaining in Express.js involves using multiple middleware functions in sequence
to process incoming HTTP requests. Each middleware function can modify the request or
response objects and either terminate the request-response cycle or pass control to the next
middleware function using the `next()` function.

Sheet Prepared By CrazyWebDev Academy


MongoDB Interview Questions
1. What is MongoDB?

MongoDB is a NoSQL database management system that uses a document-oriented data

model. It is designed to be flexible, scalable, and high-performance, making it suitable for

handling large volumes of data in diverse applications.

2. What are the key features of MongoDB?

Key features of MongoDB include its flexible schema design, support for ad-hoc queries,

scalability through sharding, high availability through replication, rich query language, indexing

capabilities, and support for geospatial queries.

3. What is BSON? How is it different from JSON?

BSON (Binary JSON) is a binary-encoded serialization of JSON-like documents. BSON extends

the JSON model to provide additional data types and support for more efficient storage and

traversal. Unlike JSON, BSON is binary-encoded, allowing for more compact data representation

and better performance.

4. Explain the structure of a MongoDB document.

A MongoDB document is a data record stored in a collection. It is a JSON-like structure

composed of field-value pairs, where fields are strings and values can be various data types,

including other documents, arrays, and binary data.

5. What is a MongoDB collection? How does it differ from a document?

A MongoDB collection is a grouping of MongoDB documents. It is analogous to a table in

relational databases. Collections do not enforce a schema, allowing documents within a

collection to have different structures. A document, on the other hand, is a single record within a

collection.

6. Explain the concept of sharding in MongoDB.

Sheet Prepared By CrazyWebDev Academy


Sharding in MongoDB is the process of distributing data across multiple machines to improve

scalability and performance. It involves splitting a collection into smaller chunks called shards,

which are then distributed across different servers or clusters.

7. What is the role of a replica set in MongoDB?

A replica set in MongoDB is a group of MongoDB instances that maintain the same data set. It

provides high availability and fault tolerance by replicating data across multiple servers. In the

event of a primary node failure, one of the secondary nodes automatically becomes the new

primary node, ensuring continuous operation.

8. What is indexing in MongoDB? Why is it important?

Indexing in MongoDB is the process of creating data structures to improve the speed of data

retrieval operations. Indexes are essential for efficiently querying large datasets by facilitating

rapid lookup and sorting of data based on specified fields.

9. Differentiate between SQL and NoSQL databases.

SQL databases are relational databases that store data in tables with predefined schemas

and use structured query language (SQL) for data manipulation. NoSQL databases, including

MongoDB, employ flexible data models and do not require predefined schemas. They are

designed for scalability, high availability, and performance in distributed environments.

10. What are the various types of NoSQL databases?

NoSQL databases can be categorized into four main types: document-oriented databases

(e.g., MongoDB), key-value stores, column-family stores, and graph databases.

11. What are the different types of MongoDB deployments?

MongoDB deployments can be standalone, replica sets, or sharded clusters. Standalone

deployments consist of a single MongoDB instance. Replica sets are groups of MongoDB

instances that maintain the same data set for high availability. Sharded clusters distribute data

across multiple servers to support horizontal scalability.

Sheet Prepared By CrazyWebDev Academy


12. How does MongoDB ensure high availability?

MongoDB ensures high availability through features like replica sets, automatic failover, and

data redundancy. Replica sets maintain multiple copies of data across different servers,

allowing for automatic promotion of secondary nodes to primary in case of primary node

failure.

13. Explain the process of data modeling in MongoDB.

Data modeling in MongoDB involves designing the structure of documents and collections to

reflect the application's data requirements. It includes identifying relationships between data,

optimizing document structure for efficient querying, and considering factors like scalability

and performance.

14. What is GridFS in MongoDB? When is it used?

GridFS is a specification for storing and retrieving large files in MongoDB. It divides files into

smaller chunks, which are then stored as separate documents in a collection. GridFS is used

when dealing with large binary data, such as images, videos, or files, that exceed the BSON

document size limit.

15. What is MapReduce in MongoDB?

MapReduce in MongoDB is a data processing paradigm for performing distributed

computations on large datasets. It involves two main stages: the map stage, where data is

processed and transformed into intermediate key-value pairs, and the reduce stage, where the

intermediate results are aggregated to produce the final output.

16. How does MongoDB ensure security?

MongoDB provides security features such as authentication, authorization, encryption, and

auditing. Authentication ensures that only authenticated users can access the database, while

authorization controls access rights and privileges. Encryption protects data both at rest and in

transit, and auditing tracks database activities for compliance and security purposes.

17. Explain the concept of Aggregation in MongoDB.

Sheet Prepared By CrazyWebDev Academy


Aggregation in MongoDB is the process of performing data processing operations on multiple

documents to compute aggregated results. It allows for complex data analysis tasks like

grouping, filtering, and computing aggregate functions such as sum, average, and count.

18. What are the different types of MongoDB queries?

MongoDB supports various types of queries, including CRUD (Create, Read, Update, Delete)

operations, aggregation queries, geospatial queries, text search queries, and MapReduce

queries.

19. What is the role of the MongoDB profiler?

The MongoDB profiler is a diagnostic tool that monitors database operations to identify

performance bottlenecks and optimize query performance. It collects data on query execution

times, index usage, and other metrics to help developers analyze and improve application

performance.

20. How does MongoDB handle transactions?

MongoDB supports multi-document transactions across multiple collections and databases

within a single replica set or sharded cluster. Transactions ensure data integrity and

consistency by allowing developers to perform atomic operations on multiple documents

within a transactional context.

21. What are the limitations of MongoDB?

MongoDB has some limitations, including lack of support for ACID transactions across

multiple documents and collections in distributed environments, limited support for JOIN

operations, and potential performance issues with large datasets and complex queries.

22. Explain the concept of Replication Factor in MongoDB.

Replication Factor in MongoDB refers to the number of copies of data maintained across

different servers or nodes within a replica set. It determines the level of data redundancy and

fault tolerance in the system. A higher replication factor increases fault tolerance but also

incurs additional storage and resource overhead.

Sheet Prepared By CrazyWebDev Academy


23. How do you monitor MongoDB?

MongoDB can be monitored using various tools and techniques, including the MongoDB

Monitoring Service (MMS), built-in monitoring features like mongostat and db.stats(),

third-party monitoring solutions, and integrating MongoDB with external monitoring and

alerting systems.

24. What are the different backup strategies in MongoDB?

Backup strategies in MongoDB include regular backups using tools like mongodump or

filesystem snapshots, continuous backups using MongoDB Atlas Backup service or third-party

backup solutions, and offsite backups to remote storage for disaster recovery purposes.

25. Explain the concept of read preference in MongoDB.

Read preference in MongoDB determines which replica set members are eligible to handle

read operations. It allows developers to specify preferences for reading data from primary or

secondary nodes based on factors like data consistency, latency, and load distribution.

26. What is the significance of the MongoDB WiredTiger storage engine?

WiredTiger is the default storage engine for MongoDB since version 3.2. It offers significant

performance improvements, concurrency control, compression, and data durability features

compared to the previous MMAPv1 storage engine.

27. What is the MongoDB Compass?

MongoDB Compass is a graphical user interface (GUI) tool for MongoDB that provides a visual

interface for performing database operations, managing data, creating queries, and analyzing

database performance.

28. How does MongoDB handle concurrency?

MongoDB handles concurrency using a multi-document locking mechanism that allows

multiple read operations to occur simultaneously but restricts write operations to ensure data

consistency and prevent conflicts.

Sheet Prepared By CrazyWebDev Academy


29. What are the different authentication mechanisms in MongoDB?

MongoDB supports various authentication mechanisms, including SCRAM (Salted Challenge

Response Authentication Mechanism), x.509 certificates, LDAP (Lightweight Directory Access

Protocol), and Kerberos authentication.

30. Explain the concept of Write Concern in MongoDB.

Write Concern in MongoDB specifies the level of acknowledgment required from the server for

write operations to be considered successful. It includes options like "acknowledged,"

"unacknowledged," "journaled," and "replica acknowledged," which determine the durability and

consistency guarantees for write operations.

Sheet Prepared By CrazyWebDev Academy

You might also like