100 MongoDB MCQ (Multiple Choice Questions) with Answers

1) What type of database is MongoDB?
  1. Relational (RDBMS)
  2. Key-Value Store
  3. Document-Oriented NoSQL
  4. Graph Database
Show Answer
Answer: c


2) In MongoDB, data is stored in which format?

  1. SQL Tables
  2. BSON (Binary JSON)
  3. XML
  4. CSV
Show Answer
Answer: b


3) What is the equivalent of a table in MongoDB?

  1. Document
  2. Collection
  3. Field
  4. Database
Show Answer
Answer: b


4) What is the equivalent of a row in MongoDB?

  1. Column
  2. Schema
  3. Document
  4. Field
Show Answer
Answer: c


5) What is the primary unique identifier field automatically added to every MongoDB document if not provided?

  1. `_uid`
  2. `_id`
  3. `id`
  4. `key`
Show Answer
Answer: b


6) What is the default data type of the `_id` field?

  1. Integer
  2. String
  3. ObjectId
  4. UUID
Show Answer
Answer: c


7) How many bytes does an ObjectId occupy?

  1. 8 bytes
  2. 12 bytes
  3. 16 bytes
  4. 64 bytes
Show Answer
Answer: b


8) Which command starts the MongoDB server process?

  1. `mongo`
  2. `mongod`
  3. `mongos`
  4. `start-mongo`
Show Answer
Answer: b


9) Which process acts as a routing service for MongoDB sharded clusters?

  1. `mongod`
  2. `mongos`
  3. `mongo-router`
  4. `mongo-cli`
Show Answer
Answer: b


10) What is the maximum size of a BSON document in MongoDB?

  1. 4 MB
  2. 8 MB
  3. 16 MB
  4. 32 MB
Show Answer
Answer: c


11) Which command displays the list of all databases?

  1. `show collections`
  2. `show dbs`
  3. `list databases`
  4. `get dbs`
Show Answer
Answer: b


12) Which command switches to a specific database named `testDB`?

  1. `switch testDB`
  2. `use testDB`
  3. `select testDB`
  4. `connect testDB`
Show Answer
Answer: b


13) How do you check which database is currently selected?

  1. `db`
  2. `current`
  3. `show db`
  4. `get db`
Show Answer
Answer: a


14) Which command is used to drop the current database?

  1. `db.drop()`
  2. `db.dropDatabase()`
  3. `db.delete()`
  4. `drop database`
Show Answer
Answer: b


15) Which method explicitly creates a collection in MongoDB?

  1. `db.createTable()`
  2. `db.newCollection()`
  3. `db.createCollection()`
  4. `db.addCollection()`
Show Answer
Answer: c


16) Which command lists all collections in the current database?

  1. `show collections`
  2. `show tables`
  3. `db.getCollections()`
  4. `list collections`
Show Answer
Answer: a


17) How do you drop a collection named `users`?

  1. `db.users.delete()`
  2. `db.users.drop()`
  3. `db.dropCollection(“users”)`
  4. `db.users.remove()`
Show Answer
Answer: b


18) What happens when you insert a document into a collection that does not exist?

  1. Throws an error
  2. Document is discarded
  3. MongoDB automatically creates the collection
  4. Asks for confirmation
Show Answer
Answer: c


19) What is a capped collection?

  1. A collection with a fixed size that overwrites old documents when full
  2. A collection restricted by access permissions
  3. A read-only collection
  4. An encrypted collection
Show Answer
Answer: a


20) Which parameter creates a capped collection using `db.createCollection()`?

  1. `{ limit: true }`
  2. `{ capped: true, size: }`
  3. `{ fixed: true }`
  4. `{ maxRows: }`
Show Answer
Answer: b


21) Which method inserts a single document into a collection?

  1. `db.collection.insertOne()`
  2. `db.collection.add()`
  3. `db.collection.append()`
  4. `db.collection.saveOne()`
Show Answer
Answer: a


22) Which method inserts multiple documents at once?

  1. `db.collection.insertMany()`
  2. `db.collection.insertAll()`
  3. `db.collection.bulkInsert()`
  4. `db.collection.addMany()`
Show Answer
Answer: a


23) If `ordered: false` is passed in `insertMany()`, what happens if one document fails?

  1. All inserts are rolled back
  2. MongoDB stops inserting remaining documents
  3. MongoDB continues inserting remaining documents
  4. The whole database locks up
Show Answer
Answer: c


24) What happens if you specify an existing `_id` during an insert operation?

  1. It overwrites the existing document
  2. It creates a duplicate key error
  3. It generates a new `_id` automatically
  4. It appends a timestamp to the `_id`
Show Answer
Answer: b


25) Which method updates a document if found, or inserts it if it doesn’t exist (when `upsert: true`)?

  1. `insertOne()`
  2. `updateOne()`
  3. `replaceOne()`
  4. Both b and c
Show Answer
Answer: d


26) Which method is used to query documents from a collection?

  1. `db.collection.select()`
  2. `db.collection.find()`
  3. `db.collection.get()`
  4. `db.collection.query()`
Show Answer
Answer: b


27) How do you return only one matching document from a collection?

  1. `db.collection.findFirst()`
  2. `db.collection.findOne()`
  3. `db.collection.getOne()`
  4. `db.collection.limit(1)`
Show Answer
Answer: b


28) What does `db.collection.find()` return if no query parameters are given?

  1. First document
  2. Last document
  3. All documents in the collection
  4. An error
Show Answer
Answer: c


29) How do you format output to make it readable in the MongoDB shell?

  1. `db.collection.find().format()`
  2. `db.collection.find().pretty()`
  3. `db.collection.find().print()`
  4. `db.collection.find().json()`
Show Answer
Answer: b


30) Which projection syntax includes only the `name` field in query results?

  1. `db.users.find({}, { name: 1 })`
  2. `db.users.find({}, { name: true })`
  3. `db.users.find({ name: 1 })`
  4. `db.users.find({}, { include: “name” })`
Show Answer
Answer: a


31) By default, is the `_id` field included in projection results?

  1. No
  2. Yes, unless explicitly excluded `{ _id: 0 }`
  3. Only if requested `{ _id: 1 }`
  4. Only in primary keys
Show Answer
Answer: b


32) How do you limit the output of a query to 5 records?

  1. `db.collection.find().max(5)`
  2. `db.collection.find().limit(5)`
  3. `db.collection.find().top(5)`
  4. `db.collection.find().take(5)`
Show Answer
Answer: b


33) Which method skips the first 10 documents in a result set?

  1. `db.collection.find().offset(10)`
  2. `db.collection.find().skip(10)`
  3. `db.collection.find().jump(10)`
  4. `db.collection.find().ignore(10)`
Show Answer
Answer: b


34) How do you sort results by `age` in ascending order?

  1. `db.users.find().sort({ age: 1 })`
  2. `db.users.find().sort({ age: -1 })`
  3. `db.users.find().sort({ age: “asc” })`
  4. `db.users.find().orderBy(“age”)`
Show Answer
Answer: a


35) How do you sort results by `age` in descending order?

  1. `db.users.find().sort({ age: 1 })`
  2. `db.users.find().sort({ age: -1 })`
  3. `db.users.find().sort({ age: “desc” })`
  4. `db.users.find().orderBy(“age DESC”)`
Show Answer
Answer: b


36) Which operator checks for equality?

  1. `$equal`
  2. `$eq`
  3. `$is`
  4. `$match`
Show Answer
Answer: b


37) Which operator selects documents where a field value is greater than a specified value?

  1. `$gt`
  2. `$gte`
  3. `$greater`
  4. `$max`
Show Answer
Answer: a


38) Which operator selects documents where a value is less than or equal to a specified value?

  1. `$lt`
  2. `$lte`
  3. `$min`
  4. `$le`
Show Answer
Answer: b


39) Which operator matches any of the values specified in an array?

  1. `$in`
  2. `$any`
  3. `$or`
  4. `$contains`
Show Answer
Answer: a


40) What is the opposite operator of `$in`?

  1. `$notin`
  2. `$nin`
  3. `$except`
  4. `$out`
Show Answer
Answer: b


41) Which logical operator returns documents that satisfy ALL given conditions?

  1. `$or`
  2. `$and`
  3. `$nor`
  4. `$all`
Show Answer
Answer: b


42) Which logical operator matches documents where NEITHER condition is true?

  1. `$not`
  2. `$nor`
  3. `$neither`
  4. `$none`
Show Answer
Answer: b


43) Which operator checks for the existence of a field in a document?

  1. `$has`
  2. `$exists`
  3. `$contains`
  4. `$isPresent`
Show Answer
Answer: b


44) Which operator selects documents based on BSON data types?

  1. `$type`
  2. `$datatype`
  3. `$isType`
  4. `$bson`
Show Answer
Answer: a


45) Which operator allows regex searching in MongoDB queries?

  1. `$like`
  2. `$regex`
  3. `$match`
  4. `$search`
Show Answer
Answer: b


46) Which operator matches arrays containing ALL specified elements?

  1. `$in`
  2. `$all`
  3. `$elemMatch`
  4. `$size`
Show Answer
Answer: b


47) Which operator checks the exact array size in a document?

  1. `$length`
  2. `$count`
  3. `$size`
  4. `$limit`
Show Answer
Answer: c


48) Which operator matches documents containing an array field with at least one element matching all criteria?

  1. `$matchArray`
  2. `$elemMatch`
  3. `$filter`
  4. `$slice`
Show Answer
Answer: b


49) How do you select documents where `age` is between 20 and 30 inclusive?

  1. `db.users.find({ age: { $between: [20, 30] } })`
  2. `db.users.find({ age: { $gte: 20, $lte: 30 } })`
  3. `db.users.find({ age: { $gt: 20, $lt: 30 } })`
  4. `db.users.find({ age: { $range: [20, 30] } })`
Show Answer
Answer: b


50) What operator evaluates a JavaScript expression inside a query?

  1. `$js`
  2. `$where`
  3. `$eval`
  4. `$script`
Show Answer
Answer: b


51) Which operator sets the value of a field in a document?

  1. `$put`
  2. `$set`
  3. `$assign`
  4. `$update`
Show Answer
Answer: b


52) Which operator deletes a specified field from a document?

  1. `$unset`
  2. `$delete`
  3. `$remove`
  4. `$drop`
Show Answer
Answer: a


53) Which operator increments a field value by a specified number?

  1. `$add`
  2. `$inc`
  3. `$plus`
  4. `$sum`
Show Answer
Answer: b


54) How do you decrement a numeric field `points` by 5?

  1. `{ $inc: { points: -5 } }`
  2. `{ $dec: { points: 5 } }`
  3. `{ $sub: { points: 5 } }`
  4. `{ $set: { points: points – 5 } }`
Show Answer
Answer: a


55) Which array operator appends a single item to an array field?

  1. `$append`
  2. `$push`
  3. `$add`
  4. `$insert`
Show Answer
Answer: b


56) Which array operator appends items to an array ONLY if they do not already exist?

  1. `$push`
  2. `$addToSet`
  3. `$addUnique`
  4. `$unique`
Show Answer
Answer: b


57) Which operator removes the first or last item from an array?

  1. `$pop`
  2. `$pull`
  3. `$shift`
  4. `$remove`
Show Answer
Answer: a


58) How do you remove all instances of a specific value from an array?

  1. `$pop`
  2. `$pull`
  3. `$remove`
  4. `$delete`
Show Answer
Answer: b


59) Which method deletes a single matching document from a collection?

  1. `db.collection.removeOne()`
  2. `db.collection.deleteOne()`
  3. `db.collection.dropOne()`
  4. `db.collection.eraseOne()`
Show Answer
Answer: b


60) Which method deletes ALL documents matching a query?

  1. `db.collection.deleteMany()`
  2. `db.collection.removeAll()`
  3. `db.collection.clear()`
  4. `db.collection.drop()`
Show Answer
Answer: a


61) What does `db.collection.deleteMany({})` do?

  1. Drops the collection schema
  2. Deletes all documents in the collection without removing the collection itself
  3. Throws a syntax error
  4. Deletes the entire database
Show Answer
Answer: b


62) Which method replaces an entire single document except the `_id` field?

  1. `updateOne()`
  2. `replaceOne()`
  3. `save()`
  4. `setOne()`
Show Answer
Answer: b


63) What is the primary benefit of creating indexes in MongoDB?

  1. Saves disk space
  2. Improves query execution speed
  3. Encrypts document data
  4. Automatically backs up data
Show Answer
Answer: b


64) Which method creates an index on a collection?

  1. `db.collection.addIndex()`
  2. `db.collection.createIndex()`
  3. `db.collection.makeIndex()`
  4. `db.collection.buildIndex()`
Show Answer
Answer: b


65) How do you create an ascending index on the `email` field?

  1. `db.users.createIndex({ email: 1 })`
  2. `db.users.createIndex({ email: “asc” })`
  3. `db.users.createIndex({ email: “ascending” })`
  4. `db.users.createIndex(“email”)`
Show Answer
Answer: a


66) What is a compound index?

  1. An index on multiple fields
  2. An index shared across collections
  3. An index created in memory
  4. An index with automatic expiration
Show Answer
Answer: a


67) Which index type enforces uniqueness for indexed field values?

  1. Primary Index
  2. Unique Index
  3. Sparse Index
  4. Hashed Index
Show Answer
Answer: b


68) How do you create a unique index on `username`?

  1. `db.users.createIndex({ username: 1 }, { unique: true })`
  2. `db.users.createUniqueIndex({ username: 1 })`
  3. `db.users.createIndex({ username: 1, unique: 1 })`
  4. `db.users.setUnique(“username”)`
Show Answer
Answer: a


69) What type of index automatically deletes documents after a specified time period?

  1. Expiry Index
  2. TTL (Time-To-Live) Index
  3. Auto-Delete Index
  4. Timed Index
Show Answer
Answer: b


70) Which index type indexes array data by creating entries for each array element?

  1. Multikey Index
  2. Array Index
  3. Compound Index
  4. List Index
Show Answer
Answer: a


71) How do you list all indexes on a collection named `orders`?

  1. `db.orders.showIndexes()`
  2. `db.orders.getIndexes()`
  3. `db.orders.listIndexes()`
  4. Both b and c
Show Answer
Answer: d


72) How do you drop an index on field `email`?

  1. `db.users.dropIndex({ email: 1 })`
  2. `db.users.deleteIndex(“email”)`
  3. `db.users.removeIndex({ email: 1 })`
  4. `db.users.clearIndex(“email”)`
Show Answer
Answer: a


73) What tool/method shows query performance statistics, such as index usage?

  1. `.explain()`
  2. `.analyze()`
  3. `.profile()`
  4. `.trace()`
Show Answer
Answer: a


74) What is a “covered query”?

  1. A query where all fields requested are part of an index, avoiding document reads
  2. A query executed within a secure transaction
  3. A query cached in RAM
  4. A query with full-text search enabled
Show Answer
Answer: a


75) What default index is created on every collection automatically?

  1. No default index
  2. Index on `_id` field
  3. Index on `createdAt` field
  4. Index on all primary keys
Show Answer
Answer: b


76) Which method is used to process data through an aggregation pipeline?

  1. `db.collection.pipeline()`
  2. `db.collection.aggregate()`
  3. `db.collection.group()`
  4. `db.collection.process()`
Show Answer
Answer: b


77) In aggregation, which stage filters documents (similar to `find()`)?

  1. `$filter`
  2. `$match`
  3. `$where`
  4. `$query`
Show Answer
Answer: b


78) Which aggregation stage groups documents by a specified key?

  1. `$collect`
  2. `$group`
  3. `$reduce`
  4. `$aggregate`
Show Answer
Answer: b


79) What field is required inside the `$group` stage to define group keys?

  1. `_id`
  2. `key`
  3. `groupKey`
  4. `id`
Show Answer
Answer: a


80) Which aggregation stage reshapes documents by including, excluding, or adding fields?

  1. `$shape`
  2. `$project`
  3. `$select`
  4. `$transform`
Show Answer
Answer: b


81) Which aggregation stage is used to sort incoming documents?

  1. `$orderBy`
  2. `$sort`
  3. `$arrange`
  4. `$order`
Show Answer
Answer: b


82) Which aggregation stage flattens an array field to output a document for each element?

  1. `$flatten`
  2. `$unwind`
  3. `$expand`
  4. `$split`
Show Answer
Answer: b


83) Which aggregation stage performs a left outer join to another collection?

  1. `$join`
  2. `$lookup`
  3. `$merge`
  4. `$combine`
Show Answer
Answer: b


84) Which parameter in `$lookup` specifies the collection in the same database to join?

  1. `from`
  2. `with`
  3. `target`
  4. `foreign`
Show Answer
Answer: a


85) Which aggregation stage outputs results directly into a specified collection?

  1. `$out`
  2. `$export`
  3. `$save`
  4. `$write`
Show Answer
Answer: a


86) Which accumulator operator counts the number of documents in a `$group` stage?

  1. `{ $sum: 1 }`
  2. `{ $count: 1 }`
  3. `{ $total: 1 }`
  4. `{ $inc: 1 }`
Show Answer
Answer: a


87) Which operator calculates the average of numeric values in a group?

  1. `$mean`
  2. `$avg`
  3. `$average`
  4. `$calcAvg`
Show Answer
Answer: b


88) Which aggregation stage restricts the number of documents passed to the next stage?

  1. `$take`
  2. `$limit`
  3. `$top`
  4. `$max`
Show Answer
Answer: b


89) What is a Replica Set in MongoDB?

  1. A set of sharded clusters
  2. A group of `mongod` instances that maintain the same data set for high availability
  3. A daily database backup process
  4. A group of read-only databases
Show Answer
Answer: b


90) How many Primary nodes can a single Replica Set have at any given time?

  1. Exactly 1
  2. Up to 3
  3. Unlimited
  4. 2
Show Answer
Answer: a


91) What happens if the Primary node fails in a Replica Set?

  1. The cluster shuts down
  2. An election takes place among secondaries to select a new Primary
  3. The database converts to read-only permanently
  4. Data is lost completely
Show Answer
Answer: b


92) What is the role of an Arbiter in a Replica Set?

  1. Stores a full copy of data
  2. Holds elections and votes, but does not replicate data
  3. Handles write operations
  4. Manages index creation
Show Answer
Answer: b


93) What is Sharding in MongoDB?

  1. Data replication for disaster recovery
  2. Horizontal partitioning of data across multiple machines
  3. Vertical scaling by adding RAM
  4. Index optimization strategy
Show Answer
Answer: b


94) What component acts as a query router for a sharded cluster?

  1. Replica Set
  2. `mongos`
  3. Config Server
  4. Data Node
Show Answer
Answer: b


95) What is a Shard Key?

  1. A security token used to access a sharded database
  2. A field or multi-field index that determines how documents are distributed across shards
  3. The primary key of the database server
  4. An encryption key for data at rest
Show Answer
Answer: b


96) What component stores metadata and configuration settings for a sharded cluster?

  1. Primary Node
  2. Config Servers
  3. Master Node
  4. Routing Table
Show Answer
Answer: b


97) Which command enables sharding on a specific database?

  1. `sh.enableSharding(“dbName”)`
  2. `db.enableSharding()`
  3. `mongo.shardDB(“dbName”)`
  4. `cluster.addShard(“dbName”)`
Show Answer
Answer: a


98) What is the default write concern level in MongoDB?

  1. `w: 0`
  2. `w: 1`
  3. `w: “majority”`
  4. `w: 2`
Show Answer
Answer: b


99) Which authentication mechanism is enabled by default in secured MongoDB setups?

  1. LDAP
  2. SCRAM (Salted Challenge Response Authentication Mechanism)
  3. Kerberos
  4. Plaintext Passwords
Show Answer
Answer: b


100) Which MongoDB utility is used to export data into BSON binary dumps for backup?

  1. `mongoexport`
  2. `mongodump`
  3. `mongostat`
  4. `mongotop`
Show Answer
Answer: b

 

100 MySQL MCQ (Multiple Choice Questions) with Answers
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment