Database - MongoDB MCQ Questions and Answers

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

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

101. Which command imports BSON data into MongoDB?

  • a) mongorestore
  • b) mongoimport
  • c) loadbson
  • d) db.import()
Answer: A - mongorestore imports binary BSON files created by mongodump.

102. What is the purpose of the $hour operator?

  • a) Extracts hour from date (0-23)
  • b) Converts to hourly averages
  • c) Creates time buckets
  • d) Measures hour intervals
Answer: A - { $hour: "$timestamp" } returns the hour portion of a date.

103. Which method creates a MongoDB Atlas cluster?

  • a) Atlas UI/API only
  • b) db.createAtlasCluster()
  • c) mongod --atlas
  • d) db.makeCluster()
Answer: A - Atlas clusters are managed through the cloud UI/API, not shell commands.

104. What does the $literal operator do?

  • a) Prevents parsing of special characters
  • b) Creates literal strings
  • c) Validates JSON syntax
  • d) Escapes BSON
Answer: A - $literal treats values as literals rather than field paths (e.g., "$field" vs { $literal: "$field" }).

105. Which operator performs set intersection?

  • a) $setIntersection
  • b) $intersect
  • c) $common
  • d) $and
Answer: A - { $setIntersection: [array1, array2] } returns common elements.

106. What is the purpose of the $indexOfArray operator?

  • a) Finds first position of element in array
  • b) Creates array indexes
  • c) Validates array contents
  • d) Counts array occurrences
Answer: A - { $indexOfArray: [array, value] } returns the index of the first match (-1 if not found).

107. Which command enables MongoDB profiling?

  • a) db.setProfilingLevel(2)
  • b) db.enableProfiling()
  • c) mongod --profile
  • d) profile.start()
Answer: A - Profiling levels: 0=off, 1=slow ops, 2=all ops (stored in system.profile collection).

108. What does the $reverseArray operator do?

  • a) Reverses element order
  • b) Creates mirrored arrays
  • c) Validates array sequence
  • d) Undoes array operations
Answer: A - { $reverseArray: array } returns a new array with elements in reverse order.

109. Which method creates a MongoDB client session?

  • a) MongoClient.startSession()
  • b) db.startSession()
  • c) session.create()
  • d) db.clientSession()
Answer: A - Sessions are created at the client level for transactions and causal consistency.

110. What is the purpose of the $dateDiff operator?

  • a) Calculates time between two dates
  • b) Formats date differences
  • c) Validates date ranges
  • d) Converts timezones
Answer: A - { $dateDiff: { startDate: date1, endDate: date2, unit: "day" } } computes intervals.

111. Which operator implements set difference?

  • a) $setDifference
  • b) $diff
  • c) $subtractArrays
  • d) $minus
Answer: A - { $setDifference: [array1, array2] } returns elements in array1 not in array2.

112. What does the $first operator return in $group?

  • a) First document's value per group
  • b) First array element
  • c) Earliest timestamp
  • d) First matching document
Answer: A - { $group: { _id: "$field", firstVal: { $first: "$target" } } }.

113. Which command lists MongoDB's available commands?

  • a) db.listCommands()
  • b) show commands
  • c) db.help()
  • d) db.commands()
Answer: A - listCommands() displays all supported commands with their requirements.

114. What is the purpose of the $zip operator?

  • a) Merges arrays element-wise
  • b) Compresses data
  • c) Creates archive files
  • d) Encodes BSON
Answer: A - { $zip: { inputs: [array1, array2] } } produces [ [elem1,elem2], ... ].

115. Which operator checks if a value is in an array?

  • a) $in
  • b) $has
  • c) $contains
  • d) $within
Answer: A - { field: { $in: [value1, value2] } } matches documents where field equals any array value.

116. What does the $min operator do in $group?

  • a) Returns the smallest value per group
  • b) Filters minimum values
  • c) Sets lower bounds
  • d) Validates ranges
Answer: A - { $min: "$field" } in $group finds the minimum value across documents.

117. Which method returns MongoDB's build info?

  • a) db.version()
  • b) db.buildInfo()
  • c) mongod --version
  • d) db.serverBuildInfo()
Answer: B - buildInfo() shows version, git hash, and compilation flags.

118. What is the purpose of the $reduce operator?

  • a) Applies an expression to each array element cumulatively
  • b) Shrinks document size
  • c) Optimizes storage
  • d) Decreases array length
Answer: A - { $reduce: { input: array, initialValue: 0, in: "$$value + $$this" } } works like JavaScript's reduce().

119. Which operator implements set equality?

  • a) $setEquals
  • b) $arrayEqual
  • c) $same
  • d) $equalSets
Answer: A - { $setEquals: [array1, array2] } returns true if arrays have same elements (order irrelevant).

120. What does the $ltrim operator do?

  • a) Removes whitespace from string start
  • b) Trims arrays
  • c) Left-aligns text
  • d) Limits document size
Answer: A - { $ltrim: { input: " text " } } returns "text ".
« First 5 6 7 8 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!