Database - MongoDB MCQ Questions and Answers

Test your knowledge of Database - [MongoDB] section with these interactive multiple-choice questions.

« First 6 7 8 9 Last »
« Previous Page Next Page »

121. Which command validates collection documents?

  • a) db.collection.validate()
  • b) db.checkDocuments()
  • c) mongod --validate
  • d) db.validateAll()
Answer: A - validate() checks data structure integrity and returns storage statistics.

122. What is the purpose of the $dayOfMonth operator?

  • a) Returns day number (1-31)
  • b) Calculates month duration
  • c) Groups by calendar days
  • d) Validates date formats
Answer: A - { $dayOfMonth: "$date" } extracts the day portion from a date.

123. Which method creates a MongoDB Atlas Data Lake?

  • a) Atlas UI/API only
  • b) db.createDataLake()
  • c) mongod --dataLake
  • d) db.makeDataLake()
Answer: A - Data Lakes are configured through the Atlas interface, not shell commands.

124. What does the $cond operator do?

  • a) Implements if-then-else logic
  • b) Checks document condition
  • c) Validates queries
  • d) Tests server health
Answer: A - { $cond: { if: condition, then: value1, else: value2 } } works like a ternary operator.

125. Which operator performs set union?

  • a) $setUnion
  • b) $union
  • c) $mergeArrays
  • d) $concat
Answer: A - { $setUnion: [array1, array2] } returns unique elements from both arrays.

126. What is the purpose of the $last operator in $group?

  • a) Returns last document's value per group
  • b) Gets final array element
  • c) Identifies most recent timestamp
  • d) Marks end of pipeline
Answer: A - { $last: "$field" } in $group stage returns the last encountered value.

127. Which command enables MongoDB's free monitoring?

  • a) db.enableFreeMonitoring()
  • b) mongod --enableMonitoring
  • c) db.monitoring.start()
  • d) db.freeMonitoring.enable()
Answer: A - Free monitoring provides basic performance metrics visible in db.serverStatus().

128. What does the $rtrim operator do?

  • a) Removes whitespace from string end
  • b) Trims arrays from right
  • c) Right-aligns text
  • d) Reduces document size
Answer: A - { $rtrim: { input: " text " } } returns " text".

129. Which method returns MongoDB's host info?

  • a) db.hostInfo()
  • b) db.serverHost()
  • c) mongod --hostinfo
  • d) db.status().host
Answer: A - hostInfo() shows OS, CPU, and memory details of the host machine.

130. What is the purpose of the $dateToParts operator?

  • a) Decomposes date into components
  • b) Converts parts to full date
  • c) Validates date segments
  • d) Formats date strings
Answer: A - { $dateToParts: { date: "$timestamp" } } returns { year, month, day, etc. }.

131. Which operator checks if arrays are subsets?

  • a) $setIsSubset
  • b) $isSubset
  • c) $containsAll
  • d) $subset
Answer: A - { $setIsSubset: [smallArray, largeArray] } returns true if all elements exist.

132. What does the $avg operator do in $group?

  • a) Calculates arithmetic mean
  • b) Returns median value
  • c) Computes moving average
  • d) Validates number ranges
Answer: A - { $avg: "$field" } computes the average of numeric values across documents.

133. Which command lists all MongoDB features?

  • a) db.features()
  • b) show features
  • c) db.listFeatures()
  • d) No direct command (use docs)
Answer: D - MongoDB doesn't provide a shell command to list all features - consult official documentation.

134. What is the purpose of the $objectToArray operator?

  • a) Converts object to key-value pairs array
  • b) Validates object structure
  • c) Creates arrays from nested objects
  • d) Flattens documents
Answer: A - { $objectToArray: { field1: "value1" } } returns [ { k: "field1", v: "value1" } ].

135. Which operator checks if arrays share elements?

  • a) $setIntersection
  • b) $anyElementTrue
  • c) $setEquals
  • d) $allElementsTrue
Answer: A - { $gt: [ { $size: { $setIntersection: [array1, array2] } }, 0 ] } checks for common elements.

136. What does the $stdDevPop operator return?

  • a) Population standard deviation
  • b) Sample standard deviation
  • c) Statistical variance
  • d) Probability distribution
Answer: A - { $stdDevPop: "$values" } calculates the population standard deviation.

137. Which method returns MongoDB's network stats?

  • a) db.serverStatus().network
  • b) db.networkStats()
  • c) mongod --network
  • d) db.connectionInfo()
Answer: A - Network metrics like bytes in/out are available in serverStatus() output.

138. What is the purpose of the $arrayToObject operator?

  • a) Converts key-value array to object
  • b) Validates array structure
  • c) Creates nested objects
  • d) Maps arrays to documents
Answer: A - Inverse of $objectToArray, turns [ { k: "field", v: "value" } ] into { field: "value" }.

139. Which operator checks if arrays are disjoint?

  • a) $setDisjoint
  • b) $noCommon
  • c) $unique
  • d) $separate
Answer: A - { $setDisjoint: [array1, array2] } returns true if arrays share no elements.

140. What does the $trim operator do?

  • a) Removes whitespace from both ends
  • b) Shortens arrays
  • c) Compacts documents
  • d) Cleans invalid chars
Answer: A - { $trim: { input: " text " } } returns "text".
« First 6 7 8 9 Last »
« Previous Page Next Page »

MongoDB MCQs - Master NoSQL Database Concepts | PCBooks

🚀 Want to master MongoDB quickly? PCBooks offers the most comprehensive free MongoDB MCQ bank covering CRUD operations, aggregation pipeline, indexing strategies, and sharding. Perfect for:

📊 MongoDB Core Concepts MCQs

👉 BSON format vs JSON differences
👉 find() vs findOne() performance comparison
👉 Replica sets and sharding architecture
👉 Free mock tests with real interview patterns

⚡ MongoDB Performance Optimization

🎯 Critical concepts covered:
- Indexing strategies (single field, compound, unique)
- Aggregation pipeline optimization ($match early, $project wisely)
- MongoDB Atlas vs self-hosted performance benchmarks
- Change streams for real-time data
🎯 Case-study based questions with explanations
🎯 Downloadable cheat sheets for quick revision

🚀 Start Your Database Journey

SQL MCQs →
DBMS Concepts MCQs →


🏆 Trusted by 55,000+ developers for MongoDB interview prep and NoSQL skill certification!