Database - MongoDB MCQ Questions and Answers

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

« First 2 3 4 5 Last »
« Previous Page Next Page »

41. Which command lists all indexes in a collection?

  • a) db.collection.getIndexes()
  • b) db.collection.listIndexes()
  • c) db.collection.indexes()
  • d) Both A and B
Answer: D - Both getIndexes() and listIndexes() display collection indexes.

42. What is the purpose of the $merge stage in aggregation?

  • a) Combines pipeline results with existing collection
  • b) Merges multiple collections
  • c) Deletes duplicate documents
  • d) Splits large documents
Answer: A - $merge writes aggregation results to a collection with options like merging or replacing.

43. Which operator checks array size in MongoDB?

  • a) $size
  • b) $length
  • c) $count
  • d) $arraySize
Answer: A - { field: { $size: 3 } } matches arrays with exactly 3 elements.

44. What does the $natural sort do?

  • a) Returns documents in disk storage order
  • b) Sorts alphabetically
  • c) Orders by insertion time
  • d) Randomizes document order
Answer: A - .sort({ $natural: 1 }) returns documents in native storage order.

45. Which method is used for bulk write operations?

  • a) bulkWrite()
  • b) executeBatch()
  • c) multiWrite()
  • d) batchExecute()
Answer: A - bulkWrite() performs multiple insert/update/delete operations in bulk.

46. What is the purpose of the $expr operator?

  • a) Allows use of aggregation expressions in queries
  • b) Executes JavaScript
  • c) Validates query syntax
  • d) Explains query execution
Answer: A - $expr enables aggregation expressions like $eq within regular queries.

47. Which command repairs a MongoDB database?

  • a) db.repairDatabase()
  • b) db.fix()
  • c) mongod --repair
  • d) Both A and C
Answer: D - Both methods repair database files (shell command and server option).

48. What does the $convert operator do?

  • a) Changes a value's data type
  • b) Converts collections
  • c) Transforms queries
  • d) Encodes BSON
Answer: A - $convert: { input: "123", to: "int" } converts values between types.

49. Which operator performs a case-insensitive regex search?

  • a) $regex with 'i' option
  • b) $iregex
  • c) $caseInsensitive
  • d) $text with $caseSensitive:false
Answer: A - { field: { $regex: /pattern/i } } enables case-insensitive matching.

50. What is the purpose of the $facet stage?

  • a) Executes multiple pipelines in a single stage
  • b) Creates document facets
  • c) Splits collections
  • d) Optimizes queries
Answer: A - $facet runs multiple aggregation pipelines within one stage.

51. Which method returns distinct field values?

  • a) distinct()
  • b) unique()
  • c) values()
  • d) getDistinct()
Answer: A - db.collection.distinct("field") returns unique values.

52. What does the $geoNear operator do?

  • a) Returns geospatial documents by proximity
  • b) Creates geographic indexes
  • c) Validates geoJSON data
  • d) Measures distances
Answer: A - $geoNear sorts documents by distance from a point (requires geospatial index).

53. Which command flushes pending writes to disk?

  • a) db.fsyncLock()
  • b) db.flush()
  • c) db.sync()
  • d) db.commit()
Answer: A - fsyncLock() locks writes and flushes data to disk (for backups).

54. What is the purpose of the $dateToString operator?

  • a) Formats date as string
  • b) Converts string to date
  • c) Validates dates
  • d) Extracts date parts
Answer: A - { $dateToString: { format: "%Y-%m-%d", date: "$field" } }.

55. Which operator checks if a field is an array?

  • a) $isArray
  • b) $type
  • c) $arrayCheck
  • d) No direct operator (use $type with "array")
Answer: D - Use { field: { $type: "array" } } to check array type.

56. What does the $binarySize operator return?

  • a) Size of a binary field in bytes
  • b) Binary data hash
  • c) Binary encoding type
  • d) Binary checksum
Answer: A - { $binarySize: "$binField" } returns the byte length.

57. Which method creates a capped collection?

  • a) db.createCollection("name", { capped: true, size: 100000 })
  • b) db.addCappedCollection()
  • c) db.collection.cap()
  • d) db.makeCapped()
Answer: A - Capped collections have fixed size and auto-overwrite oldest documents.

58. What is the purpose of the $indexOfBytes operator?

  • a) Returns byte position of substring
  • b) Creates byte indexes
  • c) Counts bytes
  • d) Validates UTF-8
Answer: A - { $indexOfBytes: [ "$str", "sub" ] } finds substring position.

59. Which command lists all running operations?

  • a) db.currentOp()
  • b) db.operations()
  • c) show processes
  • d) db.processes()
Answer: A - currentOp() displays active operations in the database.

60. What does the $toUpper operator do?

  • a) Converts string to uppercase
  • b) Capitalizes words
  • c) Converts to title case
  • d) Escapes uppercase chars
Answer: A - { $toUpper: "$field" } transforms text to uppercase.
« First 2 3 4 5 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!