Monday, October 28, 2024

TCS Wings 1 T1 MERN - Set 10

Rahul Vijayan
Follow for more updates

TCS Wings 1 T1 MERN - Set 10


  1. Noah is adding a custom middleware to check for a user’s role before accessing specific routes in Express. Where should he place this middleware in the route definitions?
  • a) Before route handler functions
  • b) After route handler functions
  • c) Inside the database configuration
  • d) In app.listen

Answer: a) Before route handler functions


  1. Mia wants her React component to update only when a specific state variable changes, avoiding unnecessary re-renders. Which hook should she use?
  • a) useEffect
  • b) useRef
  • c) useCallback
  • d) useMemo

Answer: a) useEffect


  1. Ava is testing CRUD operations on an Express API endpoint using a tool that sends HTTP requests. Which tool is commonly used for this purpose?
  • a) MongoDB Atlas
  • b) Postman
  • c) Visual Studio Code
  • d) JSON Server

Answer: b) Postman


  1. Ethan needs to merge multiple arrays in MongoDB, removing duplicate values in the final result. Which aggregation operator should he use?
  • a) $merge
  • b) $addToSet
  • c) $push
  • d) $project

Answer: b) $addToSet


  1. Olivia is creating a new document in MongoDB and wants the _id field to be auto-generated. How does MongoDB handle the _id field by default when inserting new documents?
  • a) Generates automatically
  • b) Requires manual input
  • c) Must be generated in the application code
  • d) Is optional for insertion

Answer: a) Generates automatically


  1. Grace wants to add offline capabilities to her React PWA so it can load without internet. Which technology should she implement?
  • a) LocalStorage
  • b) Session Storage
  • c) Service Workers
  • d) Redux

Answer: c) Service Workers


  1. Leo needs his Express server to send JSON data to a client request. Which method should he use to send JSON?
  • a) res.send
  • b) res.write
  • c) res.json
  • d) res.end

Answer: c) res.json


  1. Harper is performing an aggregation in MongoDB and needs to ensure only documents matching a specific condition are passed to the next stage. Which stage will help her?
  • a) $match
  • b) $project
  • c) $group
  • d) $lookup

Answer: a) $match


  1. Amelia wants to display the same component multiple times with different data based on an array in React. Which approach allows her to iterate over the array and render the component for each item?
  • a) forEach
  • b) map
  • c) filter
  • d) find

Answer: b) map


  1. Lucas is storing a sensitive token in his React app and wants to prevent it from being accessed through JavaScript. Where is the best place to store the token?
  • a) Local Storage
  • b) Session Storage
  • c) httpOnly Cookies
  • d) Redux

Answer: c) httpOnly Cookies 

TCS Wings 1 T1 MERN - Set 9

Rahul Vijayan
Follow for more updates

TCS Wings 1 T1 MERN - Set 9


  1. Leo is developing a MongoDB query to find documents where the age field is greater than 25. Which MongoDB operator should he use?
  • a) $gte
  • b) $gt
  • c) $lt
  • d) $eq

Answer: b) $gt


  1. Harper wants to set default values for props in a React component. Which approach should she use?
  • a) propTypes
  • b) defaultProps
  • c) initialState
  • d) useEffect

Answer: b) defaultProps


  1. Oliver is creating an Express route that should handle both GET and POST requests to the same endpoint. Which Express method allows him to handle multiple HTTP methods in one route?
  • a) app.all
  • b) app.use
  • c) app.route
  • d) app.listen

Answer: c) app.route


  1. Ava needs to run a function only after the first render of a React component. Which dependency array should she pass to useEffect?
  • a) [variable]
  • b) [state]
  • c) []
  • d) [props]

Answer: c) []


  1. Mason is building a MongoDB query to include only documents where a status field equals "active". Which operator will help him filter documents based on this exact match?
  • a) $match
  • b) $eq
  • c) $in
  • d) $exists

Answer: b) $eq


  1. Lucas wants to avoid re-rendering a React component when certain state values change in a parent component. Which hook will help him control re-renders efficiently?
  • a) useEffect
  • b) useMemo
  • c) useCallback
  • d) React.memo

Answer: d) React.memo


  1. Emma is using MongoDB’s $project stage in her aggregation pipeline. What is the main purpose of $project?
  • a) Filter documents
  • b) Sort documents
  • c) Select specific fields
  • d) Group documents

Answer: c) Select specific fields


  1. Jack wants to ensure his Express app handles asynchronous errors properly. Which pattern helps him wrap route functions to handle asynchronous errors effectively?
  • a) try-catch in each route
  • b) Global error middleware
  • c) Async wrapper function
  • d) Using finally

Answer: c) Async wrapper function


  1. Isla is designing a MongoDB query that should return the number of documents that match a certain criterion. Which MongoDB method will help her achieve this?
  • a) countDocuments
  • b) find
  • c) aggregate
  • d) limit

Answer: a) countDocuments


  1. Oliver is implementing pagination in MongoDB to retrieve a limited number of documents at a time. Which two methods will help him implement this feature?
  • a) skip and limit
  • b) project and group
  • c) findOne and find
  • d) sort and aggregate

Answer: a) skip and limit 

TCS Wings 1 T1 MERN - Set 8

Rahul Vijayan
Follow for more updates

TCS Wings 1 T1 MERN - Set 8


  1. Mia is creating a dynamic list in React and wants each list item to have a unique identifier to avoid warning messages. Which attribute should she assign to each item?
  • a) ref
  • b) id
  • c) className
  • d) key

Answer: d) key


  1. Jack is implementing a sorting feature in MongoDB that arranges documents by a field in ascending order. Which value should he pass to the sort method to achieve this?
  • a) 1
  • b) -1
  • c) $asc
  • d) $desc

Answer: a) 1


  1. Sofia is handling CRUD operations in her Express app. Which method should she use to update a specific field in an existing document in MongoDB?
  • a) insertOne
  • b) updateOne
  • c) deleteOne
  • d) findOne

Answer: b) updateOne


  1. Ryan needs to call an API in his React app and wants the call to occur only once when the component mounts. What should he use as the dependency array for useEffect?
  • a) [props]
  • b) [state]
  • c) []
  • d) undefined

Answer: c) []


  1. Isla is using MongoDB and wants to limit her query results to only 10 documents. Which MongoDB method allows her to control the number of results?
  • a) skip
  • b) limit
  • c) count
  • d) filter

Answer: b) limit


  1. Mason is developing a PWA and wants the app to be available offline. Which browser feature allows his app to cache assets for offline access?
  • a) Local Storage
  • b) Service Worker
  • c) Session Storage
  • d) IndexedDB

Answer: b) Service Worker


  1. Ava wants to retrieve only specific fields from documents in a MongoDB collection. Which MongoDB method allows her to control which fields are returned?
  • a) find
  • b) select
  • c) project
  • d) limit

Answer: c) project


  1. Ethan wants to perform an aggregation in MongoDB that calculates the maximum value of a field in each group. Which operator should he use within the $group stage?
  • a) $sum
  • b) $avg
  • c) $max
  • d) $min

Answer: c) $max


  1. Mia is using axios to post data to an API and wants to handle both success and error responses. Which method allows her to catch errors from the API response?
  • a) .then()
  • b) .get()
  • c) .catch()
  • d) .finally()

Answer: c) .catch()


  1. Ella needs to pass data from a parent React component to its child component. Which React concept should she use?
  • a) State
  • b) Props
  • c) Context
  • d) Lifecycle

Answer: b) Props 

TCS Wings 1 T1 MERN - Set 7

Rahul Vijayan
Follow for more updates

TCS Wings 1 T1 MERN - Set 7


  1. Mason wants to handle asynchronous errors in his Express routes without using try-catch blocks in every route. Which helper function pattern can streamline this process?
  • a) Middleware chaining
  • b) Wrapper function that returns a promise
  • c) Logging middleware
  • d) Error-handler in route itself

Answer: b) Wrapper function that returns a promise


  1. Harper is using MongoDB's $aggregate to calculate the total number of items in each category. Which stage allows her to group data by a category field?
  • a) $match
  • b) $project
  • c) $group
  • d) $sort

Answer: c) $group


  1. Noah is using axios to fetch data in his React component and notices a CORS error in the console. What should he configure in the Express server to resolve this?
  • a) Enable body-parser
  • b) Use the cors middleware
  • c) Use the helmet package
  • d) Change the HTTP method

Answer: b) Use the cors middleware


  1. Grace wants her React component to run a specific function only when a dependency array value changes. Which hook will help her achieve this?
  • a) useState
  • b) useEffect
  • c) useMemo
  • d) useCallback

Answer: b) useEffect


  1. Oliver is updating a document in MongoDB and wants only one field to be modified while leaving the rest unchanged. Which MongoDB operator should he use?
  • a) $set
  • b) $push
  • c) $pull
  • d) $unset

Answer: a) $set


  1. Ella wants her React component to store some data that should only reset when the component unmounts. Which React feature will help her achieve this?
  • a) useState
  • b) useEffect
  • c) useRef
  • d) useContext

Answer: c) useRef


  1. Ava wants to ensure a middleware runs on every request to her Express server. Where should she place this middleware in her server configuration?
  • a) Before all route definitions
  • b) After all route definitions
  • c) Inside each route handler
  • d) Inside app.listen

Answer: a) Before all route definitions


  1. Lucas is developing a CRUD API using Express and MongoDB. Which HTTP method is used to delete a specific document based on an ID in a RESTful API?
  • a) POST
  • b) PUT
  • c) DELETE
  • d) GET

Answer: c) DELETE


  1. Amelia is using MongoDB and wants to delete multiple documents that match a specific criterion. Which method should she use?
  • a) delete
  • b) deleteOne
  • c) deleteMany
  • d) remove

Answer: c) deleteMany


  1. Ethan is setting up an API in Express that requires authentication. Which HTTP status code should he return if the user provides invalid credentials?
  • a) 200
  • b) 403
  • c) 401
  • d) 404

Answer: c) 401 

TCS Wings 1 T1 MERN - Set 6

Rahul Vijayan
Follow for more updates

TCS Wings 1 T1 MERN - Set 6 


  1. Jake is using MongoDB to group documents by a field and calculate the total sum of another field within each group. Which aggregation pipeline stage should he use?
  • a) $sum
  • b) $group
  • c) $match
  • d) $project

Answer: b) $group


  1. Ava is implementing a search filter in her MongoDB collection where she wants to retrieve documents that match any one of several values for a given field. Which MongoDB operator will help her achieve this?
  • a) $and
  • b) $in
  • c) $or
  • d) $eq

Answer: b) $in


  1. Lucas wants to add an Express middleware that logs every request method and URL. Where should he place the middleware for it to log each request globally?
  • a) After defining routes
  • b) Before defining routes
  • c) Inside each route
  • d) Inside the server.js file only

Answer: b) Before defining routes


  1. Amelia needs to display a large list of items in a React component without slowing down the UI. Which React feature can help her optimize rendering performance?
  • a) useEffect
  • b) useCallback
  • c) Virtual DOM
  • d) Component Lifecycle

Answer: c) Virtual DOM


  1. Ethan wants to render different components in his React app based on specific URL paths. Which library is commonly used to handle routing in React?
  • a) Axios
  • b) react-router-dom
  • c) Express
  • d) MongoDB

Answer: b) react-router-dom


  1. Mia is setting up server-side validation in her Express app to prevent users from submitting invalid data. Which Express feature allows her to handle validation errors centrally?
  • a) Route handlers
  • b) Middleware
  • c) Controllers
  • d) Database

Answer: b) Middleware


  1. Sofia wants to sort documents in her MongoDB collection by the date in descending order. Which MongoDB method allows her to sort documents by a specified field?
  • a) find
  • b) sort
  • c) update
  • d) aggregate

Answer: b) sort


  1. Ryan wants to store the user authentication token on the client side and make it accessible across page reloads. Which storage option is recommended for sensitive tokens in a PWA?
  • a) Local Storage
  • b) Session Storage
  • c) httpOnly Cookies
  • d) IndexedDB

Answer: c) httpOnly Cookies


  1. Isla needs to display a loading message while waiting for data to be fetched from an API in her React component. Which state should she use to track this process?
  • a) useEffect
  • b) loading
  • c) isLoading
  • d) data

Answer: c) isLoading


  1. Leo is debugging an Express route that returns a 404 error when he tries to access it. Which method should he use to verify that the route matches the URL and HTTP method correctly?
  • a) app.post
  • b) app.put
  • c) app.use
  • d) app.get

Answer: d) app.get

TCS Wings 1 T1 MERN - Set 5

Rahul Vijayan
Follow for more updates

TCS Wings 1 T1 MERN - Set 5 


  1. Jack is designing an API using Express and wants to secure routes with token-based authentication. Which middleware is best suited for validating tokens?
  • a) cors
  • b) helmet
  • c) Custom middleware that checks for valid tokens
  • d) express.static

Answer: c) Custom middleware that checks for valid tokens


  1. Chloe needs to pass a function as a prop to a child component in React. Which data type should she use in the prop?
  • a) Object
  • b) Function
  • c) String
  • d) Array

Answer: b) Function


  1. Ethan is using Express to build a REST API and wants to return JSON data. Which method should he use to send JSON responses?
  • a) res.write
  • b) res.end
  • c) res.sendFile
  • d) res.json

Answer: d) res.json


  1. Mia has a list of items displayed in a React component. She wants to ensure each item has a unique key to avoid rendering issues. Which attribute should she use for each item?
  • a) id
  • b) ref
  • c) key
  • d) className

Answer: c) key


  1. Alex needs to store user session data on the client side for a PWA. Which storage method is recommended for sensitive information like tokens?
  • a) Local Storage
  • b) Session Storage
  • c) Cookies with httpOnly and Secure flags
  • d) IndexedDB

Answer: c) Cookies with httpOnly and Secure flags


  1. Sara wants to perform an operation in MongoDB to retrieve documents where a certain field exists. Which operator should she use?
  • a) $exists
  • b) $in
  • c) $gte
  • d) $lte

Answer: a) $exists


  1. Liam is handling errors globally in his Express app. What should he pass as the first argument to the error-handling middleware function?
  • a) req
  • b) res
  • c) error
  • d) next

Answer: c) error


  1. Emma is optimizing her API calls with Axios in React and wants to cancel an API request if the component unmounts. Which method will allow her to achieve this?
  • a) AbortController
  • b) Promise.all
  • c) useMemo
  • d) React.memo

Answer: a) AbortController


  1. Noah is implementing a search function in MongoDB that performs case-insensitive searches. Which MongoDB feature will help him achieve this?
  • a) $regex
  • b) $text
  • c) $caseSensitive
  • d) $group

Answer: a) $regex


  1. Lily is handling form validation in her React app and wants to display an error message if a user leaves an input field blank. Which method is commonly used for client-side validation in React?
  • a) window.alert
  • b) setState
  • c) input validation with controlled components
  • d) console.log

Answer: c) input validation with controlled components

TCS Wings 1 T1 MERN - Set 4

Rahul Vijayan
Follow for more updates

TCS Wings 1 T1 MERN - Set 4 

  1. Mason is using MongoDB and needs to filter documents by a field value. Which method should he use to filter data within the MongoDB collection?
  • a) aggregate
  • b) find
  • c) sort
  • d) group

Answer: b) find


  1. Isla is optimizing her React app by using useCallback to memoize a function that gets called in a useEffect. What does useCallback specifically help prevent?
  • a) Prevents component unmounting
  • b) Prevents unnecessary re-renders of a function
  • c) Prevents memory leaks
  • d) Prevents updating the state

Answer: b) Prevents unnecessary re-renders of a function


  1. Oliver is using Express and wants to set up a route that requires authentication. Which status code should he return if a user tries to access it without being logged in?
  • a) 200
  • b) 401
  • c) 404
  • d) 500

Answer: b) 401


  1. Grace wants to apply custom error handling to an asynchronous route in her Express app. What should she use to catch errors in asynchronous functions?
  • a) try-catch block
  • b) await
  • c) setTimeout
  • d) throw

Answer: a) try-catch block


  1. Leo is fetching data from an API in his React component using useEffect. He notices the data fetch runs on every render. What is the correct way to fetch data only once when the component mounts?
  • a) Add [] as the dependency array in useEffect
  • b) Call the API directly in the component body
  • c) Use useMemo instead of useEffect
  • d) Use useCallback

Answer: a) Add [] as the dependency array in useEffect


  1. Ava is using MongoDB to store data and wants to update multiple documents that match a specific condition. Which MongoDB method should she use?
  • a) update
  • b) updateOne
  • c) updateMany
  • d) replaceOne

Answer: c) updateMany


  1. Charlie is working with a large dataset in MongoDB and needs to limit the number of documents returned by a query. Which MongoDB method should he use to achieve this?
  • a) limit
  • b) aggregate
  • c) sort
  • d) group

Answer: a) limit


  1. Ella wants to serve a PWA on her website, so it’s installable on mobile devices. Which file is required to set up a PWA?
  • a) manifest.json
  • b) index.html
  • c) style.css
  • d) app.js

Answer: a) manifest.json


  1. Liam is using Express with middleware to handle request data in JSON format. Where should he place the middleware in his Express app for it to parse JSON?
  • a) Before route definitions
  • b) After route definitions
  • c) Only in error-handling routes
  • d) Inside each route definition

Answer: a) Before route definitions


  1. Emily is using MongoDB and needs to count the number of documents that match certain criteria. Which method should she use?
  • a) countDocuments
  • b) find
  • c) aggregate
  • d) distinct

Answer: a) countDocuments

TCS Wings 1 T1 MERN - Set 10

Rahul Vijayan Follow for more updates TCS Wings 1 T1 MERN - Set 10 Noah is adding a custom middleware to check for a user’s role before acce...