Database - MongoDB MCQ Questions and Answers

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

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

61. Which command creates a time-series collection?

  • a) db.createCollection("logs", { timeseries: { timeField: "timestamp" } })
  • b) db.createTimeseries()
  • c) db.makeTimeSeries()
  • d) db.collection.timeseries()
Answer: A - Time-series collections optimize sequential time-based data storage.

62. What is the purpose of the $densify operator?

  • a) Adds missing values in time-series data
  • b) Compresses documents
  • c) Encrypts field values
  • d) Normalizes data
Answer: A - $densify inserts documents if values are missing in a range (e.g., timestamps).

63. Which method returns execution statistics for a query?

  • a) explain("executionStats")
  • b) stats()
  • c) analyze()
  • d) executionInfo()
Answer: A - db.collection.find().explain("executionStats") shows performance metrics.

64. What does the $rand operator do?

  • a) Generates random float between 0 and 1
  • b) Selects random documents
  • c) Shuffles array elements
  • d) Creates random strings
Answer: A - { $rand: {} } produces a pseudo-random number in aggregation.

65. Which command starts a MongoDB transaction?

  • a) session.startTransaction()
  • b) db.beginTransaction()
  • c) transaction.start()
  • d) start.transaction()
Answer: A - Transactions require a session: const session = db.getMongo().startSession().

66. What is the purpose of the $accumulator operator?

  • a) Custom aggregation logic with JavaScript
  • b) Sums values automatically
  • c) Counts documents
  • d) Accumulates system stats
Answer: A - $accumulator allows custom aggregation functions (e.g., weighted averages).

67. Which operator validates documents against a JSON Schema?

  • a) $jsonSchema
  • b) $validate
  • c) $matchSchema
  • d) $checkSchema
Answer: A - { $jsonSchema: { ... } } enforces document structure during queries.

68. What does the $linearFill operator do?

  • a) Fills nulls using linear interpolation
  • b) Draws linear graphs
  • c) Creates linear indexes
  • d) Optimizes linear searches
Answer: A - $linearFill computes missing values between known points in time-series data.

69. Which method creates a search index?

  • a) db.collection.createSearchIndex()
  • b) db.collection.searchIndex()
  • c) db.createSearchIndex()
  • d) makeSearchIndex()
Answer: A - Search indexes power MongoDB Atlas full-text search capabilities.

70. What is the purpose of the $unionWith stage?

  • a) Combines results from multiple collections
  • b) Joins collections permanently
  • c) Merges schemas
  • d) Unifies indexes
Answer: A - $unionWith performs a union of pipelines from different collections.

71. Which operator rounds numbers to integer?

  • a) $round
  • b) $trunc
  • c) $floor
  • d) All of the above
Answer: D - All these operators convert to integers with different rounding behaviors.

72. What does the $getField operator do?

  • a) Dynamically accesses fields using string names
  • b) Gets field metadata
  • c) Validates field existence
  • d) Extracts subfields
Answer: A - { $getField: { field: "name", input: "$object" } } accesses nested fields.

73. Which command changes stream settings?

  • a) db.adminCommand({ setChangeStream: true })
  • b) db.enableChangeStream()
  • c) mongod --changeStream
  • d) db.setStreaming()
Answer: A - Change streams require configuration at database or deployment level.

74. What is the purpose of the $tsIncrement operator?

  • a) Extracts increment value from timestamp
  • b) Creates incremental timestamps
  • c) Auto-increments fields
  • d) Measures time intervals
Answer: A - $tsIncrement gets the increment portion of a MongoDB timestamp (for change streams).

75. Which method returns change stream events?

  • a) db.collection.watch()
  • b) db.collection.changes()
  • c) db.getChanges()
  • d) db.stream()
Answer: A - watch() returns a cursor for real-time data changes (inserts/updates/deletes).

76. What does the $binary operator represent?

  • a) Binary data (BSON BinData type)
  • b) Binary comparisons
  • c) Binary logs
  • d) Binary indexes
Answer: A - { $binary: "base64data", $type: "00" } stores binary payloads.

77. Which operator implements bitwise operations?

  • a) $bitsAllSet
  • b) $bit
  • c) $bitsAnyClear
  • d) All of the above
Answer: D - MongoDB provides multiple bitwise query operators.

78. What is the purpose of the $meta operator?

  • a) Accesses metadata like text search scores
  • b) Defines document metadata
  • c) Stores schema information
  • d) Validates document structure
Answer: A - { $meta: "textScore" } retrieves computed values like relevance scores.

79. Which command enables client-side field-level encryption?

  • a) mongod --enableEncryption
  • b) db.enableFieldEncryption()
  • c) Requires driver configuration
  • d) db.encryptFields()
Answer: C - Field-level encryption is configured in the MongoDB driver/client.

80. What does the $function operator allow?

  • a) Custom JavaScript in aggregations
  • b) Function indexing
  • c) Stored procedures
  • d) Trigger definitions
Answer: A - $function executes custom JavaScript functions in aggregation pipelines (requires server-side scripting enabled).
« First 3 4 5 6 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!