Database - MongoDB MCQ Questions and Answers

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

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

141. Which command converts a replica set to a sharded cluster?

  • a) sh.addShard()
  • b) mongos --convert
  • c) No single command (multi-step process)
  • d) db.convertToSharded()
Answer: C - Requires deploying config servers, starting mongos, and adding shards with sh.addShard().

142. What is the purpose of the $dayOfYear operator?

  • a) Returns day number (1-366)
  • b) Calculates year progress
  • c) Groups by fiscal year
  • d) Validates year length
Answer: A - { $dayOfYear: "$date" } gives the numeric day within a year (Julian day).

143. Which method configures MongoDB Atlas Triggers?

  • a) Atlas UI/API only
  • b) db.createTrigger()
  • c) mongod --triggers
  • d) db.triggers.setup()
Answer: A - Triggers are configured through Atlas interface for event-driven functions.

144. What does the $ifNull operator do?

  • a) Returns alternative if expression is null
  • b) Checks for null documents
  • c) Validates non-null fields
  • d) Filters null values
Answer: A - { $ifNull: [ "$field", "default" ] } provides fallback values.

145. Which operator performs element-wise array comparison?

  • a) $cmp
  • b) $compareArrays
  • c) $arrayCmp
  • d) $eq
Answer: A - { $cmp: [array1, array2] } returns 0 if equal, -1/1 if less/greater.

146. What is the purpose of the $addFields stage?

  • a) Adds new fields to documents
  • b) Creates collections
  • c) Merges documents
  • d) Extends schemas
Answer: A - Similar to $project but preserves existing fields by default.

147. Which command lists MongoDB's storage engines?

  • a) db.serverStatus().storageEngine
  • b) show engines
  • c) db.listEngines()
  • d) mongod --listEngines
Answer: A - Active engine is shown in serverStatus() (WiredTiger/inMemory/etc).

148. What does the $substrBytes operator do?

  • a) Extracts substring by byte length
  • b) Counts bytes
  • c) Validates UTF-8
  • d) Splits binary data
Answer: A - { $substrBytes: ["string", startByte, length] } handles multi-byte characters safely.

149. Which method returns MongoDB's sharding status?

  • a) sh.status()
  • b) db.shardingInfo()
  • c) mongos --status
  • d) db.getShardingState()
Answer: A - sh.status() displays shard distribution, chunks, and balances.

150. What is the purpose of the $dateFromParts operator?

  • a) Constructs date from components
  • b) Extracts date segments
  • c) Validates partial dates
  • d) Converts timezones
Answer: A - { $dateFromParts: { year: 2023, month: 6, day: 15 } } builds a Date.

151. Which operator checks array position conditions?

  • a) $position
  • b) $arrayElemAt
  • c) No direct operator (use $slice + $arrayElemAt)
  • d) $index
Answer: C - Combine $slice and $arrayElemAt for positional checks.

152. What does the $stdDevSamp operator return?

  • a) Sample standard deviation
  • b) Population standard deviation
  • c) Statistical mean
  • d) Variance estimate
Answer: A - { $stdDevSamp: "$values" } calculates standard deviation for a sample (n-1 denominator).

153. Which command lists all shards in a cluster?

  • a) db.adminCommand({ listShards: 1 })
  • b) sh.listShards()
  • c) db.shards()
  • d) show shards
Answer: A - Requires admin database access to list all shard servers.

154. What is the purpose of the $split operator?

  • a) Divides string by delimiter
  • b) Partitions collections
  • c) Separates shard chunks
  • d) Splits binary data
Answer: A - { $split: ["a,b,c", ","] } returns ["a","b","c"].

155. Which operator checks if all array elements are true?

  • a) $allElementsTrue
  • b) $all
  • c) $and
  • d) $every
Answer: A - { $allElementsTrue: [true, false] } returns false.

156. What does the $sum operator do in $group?

  • a) Calculates arithmetic sum
  • b) Counts documents
  • c) Aggregates totals
  • d) Validates numbers
Answer: A - { $sum: "$field" } adds all numeric values across documents.

157. Which method returns MongoDB's connection pool stats?

  • a) db.serverStatus().connections
  • b) db.connectionPool()
  • c) mongod --connections
  • d) db.poolStats()
Answer: A - Connection metrics are available in serverStatus() output.

158. What is the purpose of the $concat operator?

  • a) Joins strings end-to-end
  • b) Merges arrays
  • c) Combines collections
  • d) Links documents
Answer: A - { $concat: ["a","b"] } returns "ab".

159. Which operator checks if any array element is true?

  • a) $anyElementTrue
  • b) $or
  • c) $some
  • d) $in
Answer: A - { $anyElementTrue: [false, true] } returns true.

160. What does the $strLenBytes operator return?

  • a) String length in bytes
  • b) Character count
  • c) UTF-8 validity
  • d) Binary size
Answer: A - { $strLenBytes: "MongoDB" } returns 7 (1 byte per ASCII char).
« First 7 8 9 10 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!