Database - MongoDB MCQ Questions and Answers

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

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

21. Which command creates a new collection in MongoDB?

  • a) db.createCollection()
  • b) db.newCollection()
  • c) db.collection.create()
  • d) db.addCollection()
Answer: A - db.createCollection("name") explicitly creates a new collection.

22. What is the purpose of the $unset operator in MongoDB?

  • a) Removes a field from documents
  • b) Deletes documents
  • c) Drops a collection
  • d) Updates array elements
Answer: A - { $unset: { field: "" } } removes the specified field.

23. Which method returns a single document in MongoDB?

  • a) findOne()
  • b) get()
  • c) fetch()
  • d) first()
Answer: A - findOne() returns the first document matching the query.

24. What does the $addToSet operator do?

  • a) Adds unique elements to an array
  • b) Creates a new set
  • c) Merges collections
  • d) Updates multiple fields
Answer: A - $addToSet adds elements to an array only if they don't already exist.

25. Which command displays MongoDB version?

  • a) db.version()
  • b) mongod --version
  • c) mongo --version
  • d) All of the above
Answer: D - All these commands show version information in different contexts.

26. What is the purpose of the $project stage in aggregation?

  • a) Selects specific fields
  • b) Filters documents
  • c) Groups documents
  • d) Sorts results
Answer: A - $project reshapes documents by including/excluding fields.

27. Which operator performs a logical OR operation?

  • a) $or
  • b) $and
  • c) $not
  • d) $nor
Answer: A - $or: [ {cond1}, {cond2} ] matches documents satisfying any condition.

28. What is the purpose of the $text operator?

  • a) Performs text search
  • b) Formats strings
  • c) Validates text fields
  • d) Converts to lowercase
Answer: A - $text performs text search on fields with a text index.

29. Which method counts documents in a collection?

  • a) countDocuments()
  • b) size()
  • c) length()
  • d) total()
Answer: A - countDocuments() returns the count matching the query.

30. What does the $slice operator do?

  • a) Returns subset of an array
  • b) Cuts documents
  • c) Divides collections
  • d) Splits strings
Answer: A - $slice limits array elements during projection.

31. Which command displays current database stats?

  • a) db.stats()
  • b) show stats
  • c) db.info()
  • d) stats()
Answer: A - db.stats() shows storage size, collections count, etc.

32. What is the purpose of the $regex operator?

  • a) Pattern matching in strings
  • b) Validating documents
  • c) Index optimization
  • d) Data encryption
Answer: A - $regex provides regular expression capabilities for pattern matching.

33. Which method updates all matching documents?

  • a) updateMany()
  • b) updateAll()
  • c) modifyMany()
  • d) changeMany()
Answer: A - updateMany() updates all documents matching the filter.

34. What does the $elemMatch operator do?

  • a) Matches documents containing array elements that satisfy all conditions
  • b) Merges array elements
  • c) Filters array elements
  • d) Sorts array elements
Answer: A - $elemMatch matches documents where at least one array element matches all criteria.

35. Which command drops a database in MongoDB?

  • a) db.dropDatabase()
  • b) db.remove()
  • c) db.delete()
  • d) db.destroy()
Answer: A - db.dropDatabase() deletes the current database.

36. What is the purpose of the $sort stage in aggregation?

  • a) Orders documents
  • b) Filters documents
  • c) Groups documents
  • d) Limits documents
Answer: A - $sort arranges documents in ascending or descending order.

37. Which operator increments a field's value?

  • a) $inc
  • b) $add
  • c) $plus
  • d) $increase
Answer: A - { $inc: { field: 1 } } increments the field by the specified amount.

38. What does the $out stage do in aggregation?

  • a) Writes results to a collection
  • b) Excludes fields
  • c) Outputs to console
  • d) Ends the pipeline
Answer: A - $out writes aggregation results to a specified collection.

39. Which method replaces a document?

  • a) replaceOne()
  • b) updateOne()
  • c) changeOne()
  • d) modifyOne()
Answer: A - replaceOne() completely replaces the matched document.

40. What is the purpose of the $bucket stage in aggregation?

  • a) Groups documents into buckets
  • b) Stores data in chunks
  • c) Divides collections
  • d) Optimizes queries
Answer: A - $bucket categorizes documents into groups based on specified boundaries.
« First 1 2 3 4 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!