
















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth assessment of MongoDB architecture, CRUD operations, indexing, aggregation pipeline, data modeling, replication, sharding, performance tuning, and security configurations. The exam includes query optimization tasks, JSON document handling, schema design questions, and troubleshooting exercises aligned with MongoDB certification standards.
Typology: Exams
1 / 88
This page cannot be seen from the preview
Don't miss anything!

















































































Question 1. Which of the following best describes the primary advantage of MongoDB’s document model over a traditional relational model? A) Fixed schema enforcement B) Ability to store binary large objects only C) Flexible schema that allows varying fields per document D) Automatic generation of foreign key constraints Answer: C Explanation: MongoDB’s document model is schema‑less, meaning each document can have a different set of fields, providing flexibility that relational tables lack. Question 2. In BSON, which data type is used to uniquely identify a document? A) String B) ObjectId C) UUID D) Binary Answer: B Explanation: ObjectId is a 12‑byte identifier automatically generated for the _id field if not supplied, ensuring uniqueness across collections. Question 3. Which component of the MongoDB architecture receives client queries and routes them to the appropriate shard? A) Config Server B) mongod process C) mongos query router D) Primary replica set member Answer: C
Explanation: mongos acts as the query router in a sharded cluster, directing operations to the correct shard based on the shard key. Question 4. What does the following connection string specify? mongodb://user:pwd@host1:27017,host2:27017/?replicaSet=rs0 A) A single‑node deployment with authentication B) A sharded cluster connection C) A replica set named rs0 with two members D) A TLS‑encrypted connection Answer: C Explanation: The URI lists two hosts and includes replicaSet=rs0, indicating a replica set named rs0. Question 5. Which MongoDB shell command inserts a single document into the products collection? A) db.products.save({name:"Pen"}) B) db.products.insertOne({name:"Pen"}) C) db.products.insert({name:"Pen"}) D) db.products.add({name:"Pen"}) Answer: B Explanation: insertOne() is the explicit command for inserting a single document; save() is deprecated, and insert() can insert one or many but is not recommended. Question 6. When performing insertMany(), which write concern guarantees that the write is acknowledged by a majority of replica set members? A) {w:0} B) {w:1} C) {w:"majority"}
B) top(10) C) slice(10) D) head(10) Answer: A Explanation: limit() restricts the number of documents returned by the cursor. Question 10. What does the $inc update operator do? A) Increments a numeric field by a specified amount B) Inserts a new document if none matches C) Includes a field in the projection D) Initializes a field with a null value Answer: A Explanation: $inc atomically adds a value to a numeric field. Question 11. Which update method replaces an entire document, discarding fields not specified in the replacement? A) updateOne() with $set B) replaceOne() C) updateMany() with $unset D) findOneAndUpdate() with $setOnInsert Answer: B Explanation: replaceOne() replaces the matched document with the supplied document; fields omitted are removed. Question 12. If you need to delete all documents where status equals "inactive" from the sessions collection, which command is appropriate?
A) db.sessions.remove({status:"inactive"}) B) db.sessions.deleteOne({status:"inactive"}) C) db.sessions.deleteMany({status:"inactive"}) D) db.sessions.drop({status:"inactive"}) Answer: C Explanation: deleteMany() removes all matching documents; deleteOne() would remove only a single match. Question 13. Which relationship pattern is best represented by embedding an array of address objects inside a customers document? A) One‑to‑One B) One‑to‑Many (embedding) C) Many‑to‑Many (referencing) D) Hierarchical tree Answer: B Explanation: Embedding an array of subdocuments models a one‑to‑many relationship where the “many” side is stored within the “one” side. Question 14. When would referencing (using ObjectId) be preferred over embedding in MongoDB schema design? A) When the related data is frequently read together B) When the related data is small and immutable C) When the related data changes often and is large D) When you need to enforce foreign key constraints Answer: C Explanation: Referencing avoids large document growth and reduces the cost of updating frequently changing data.
Answer: B Explanation: MongoDB indexes each array element, enabling efficient queries on any value within the array. Question 18. Which index type would you use to support full‑text search on the description field? A) Hashed index B) Text index C) Geospatial index D) Wildcard index Answer: B Explanation: A text index enables language‑aware search on string content. Question 19. In a compound index {a:1, b:-1, c:1}, which query pattern can fully utilize the index without a scan? A) {b: {$gt:5}} B) {a:5, b:{$lt:10}} C) {c:3} D) {b:5, a:5} Answer: B Explanation: The query uses the prefix fields a and b in the same order as the index, allowing a covered index scan. Question 20. What does a TTL (Time‑To‑Live) index do? A) Encrypts indexed fields automatically B) Automatically deletes documents after a specified number of seconds C) Limits the number of documents in a collection
D) Forces a rebuild of the index every hour Answer: B Explanation: TTL indexes remove documents once the indexed date field exceeds the defined expiration time. Question 21. When running db.collection.find({status:"A"}).explain("executionStats"), which field in the output indicates whether an index was used? A) stage B) cursor C) indexName D) totalDocsExamined Answer: B Explanation: The cursor field shows the type of cursor, e.g., BtreeCursor (index used) or BasicCursor (collection scan). Question 22. A “covered query” is one where: A) All fields returned are indexed and the query does not need to fetch the documents B) The query uses a geospatial index C) The query returns more than 10,000 documents D) The query is executed on a sharded cluster only Answer: A Explanation: If both the filter and projection are satisfied by the index, MongoDB can return results without reading the full documents. Question 23. Which aggregation stage is used to reshape each document, adding a new field fullName that concatenates first and last? A) $group
A) Deconstructs an array field into separate documents B) Executes a left‑outer join with another collection C) Writes the aggregation result to a new collection D) Adds a new field with a constant value Answer: B Explanation: $lookup enables joining data from another collection based on a local‑foreign field relationship. Question 27. What is the purpose of the $facet stage in an aggregation pipeline? A) To limit the number of documents returned B) To execute multiple sub‑pipelines in parallel and return a combined result C) To unwind nested arrays recursively D) To sort documents by multiple fields Answer: B Explanation: $facet allows defining several independent pipelines that run on the same input and produce separate result sets. Question 28. In a replica set, which member can accept write operations? A) Primary only B) Secondary only C) Any member with readPreference “secondaryPreferred” D) Arbiter only Answer: A Explanation: Only the primary handles writes; secondaries replicate data and can serve reads depending on read preference.
Question 29. During a replica set election, which component determines the new primary? A) Config Server B) Oplog C) Election algorithm based on priority and optime D) mongos router Answer: C Explanation: The election algorithm selects the member with the highest priority and most up‑to‑date optime to become primary. Question 30. Which write concern ensures that a write is persisted to the journal on the primary before acknowledgment? A) {w:0} B) {w:1, j:true} C) {w:"majority"} D) {w:2, j:false} Answer: B Explanation: Setting j:true requests acknowledgment only after the write is committed to the journal. Question 31. A read preference of secondaryPreferred means: A) All reads go to the primary unless it is unavailable B) Reads are always routed to secondaries only C) Reads are sent to a secondary if one is available, otherwise to the primary D) Reads are distributed evenly across all members Answer: C Explanation: secondaryPreferred tries a secondary first; if none are available, it falls back to the primary.
Explanation: High cardinality and evenly distributed values prevent a single shard from receiving a disproportionate amount of traffic. Question 35. A hashed shard key is most appropriate when: A) Queries frequently use range filters on the key B) You need to preserve natural ordering of the key values C) You want an even distribution without caring about range queries D) The key is a compound of multiple fields Answer: C Explanation: Hashing spreads documents uniformly across shards but does not support efficient range queries. Question 36. Which of the following statements about chunk migrations in a sharded cluster is true? A) Chunks are migrated only when a new shard is added B) The balancer moves chunks to achieve even data distribution C) Chunk migrations require manual intervention via moveChunk command only D) Chunks are immutable after creation Answer: B Explanation: The balancer automatically migrates chunks between shards to maintain balanced storage and load. Question 37. In a sharded environment, a query that includes the shard key in its filter will: A) Be routed to all shards (scatter‑gather) B) Be targeted to a single shard (or subset) C) Require a $lookup to retrieve data
D) Fail if the shard key is not indexed Answer: B Explanation: Including the shard key allows the router to target the specific shard(s) that own the matching chunk(s), avoiding a scatter‑gather. Question 38. Which authentication mechanism uses X.509 certificates for client verification? A) SCRAM-SHA- 256 B) LDAP C) MONGODB‑X D) Kerberos Answer: C Explanation: MONGODB-X509 authenticates clients via X.509 certificates. Question 39. To enable TLS/SSL encryption for a MongoDB server, which option must be added to the configuration file? A) net.ssl.mode: "requireSSL" B) security.authorization: "enabled" C) storage.wiredTiger.engineConfig.cacheSizeGB: 2 D) replication.oplogSizeMB: 1024 Answer: A Explanation: Setting net.ssl.mode to "requireSSL" forces encrypted connections. Question 40. Which tool is most appropriate for creating a point‑in‑time backup of a replica set? A) mongodump with --out option B) File system snapshot of the data directory while the primary is stopped C) mongodump with --oplog flag
B) $accumulator C) $cumulativeSum (available in MongoDB 5.0) D) $push Answer: C Explanation: $cumulativeSum computes a running total over the ordered stream of documents. Question 44. What does the $unwind stage do to an array field named items? A) Removes the field from the document B) Converts each array element into a separate document while preserving other fields C) Merges array elements into a single string D) Sorts the array in ascending order Answer: B Explanation: $unwind deconstructs the array so each element becomes its own document, duplicating the rest of the fields. Question 45. When using $lookup with pipeline option (available in MongoDB 5.0+), what advantage does it provide over the simple localField/foreignField form? A) Allows joining on multiple fields and applying additional filters in the foreign collection B) Reduces network latency by performing the join on the client side C) Enables full‑text search during the join D) Automatically creates a multikey index on the foreign field Answer: A Explanation: The pipeline form lets you specify an aggregation pipeline for the foreign collection, supporting complex matching and transformations.
Question 46. Which of the following is a valid reason to use a TTL index on a collection storing session tokens? A) To enforce uniqueness of tokens B) To automatically delete expired sessions after a fixed duration C) To speed up queries that filter by token value D) To compress the stored documents Answer: B Explanation: TTL indexes automatically remove documents once the indexed date field exceeds the defined expiration period, ideal for session cleanup. Question 47. In a sharded cluster, what is the effect of setting balancer to false in the config server? A) Prevents any new shards from being added B) Stops automatic chunk migrations, freezing the current data distribution C) Disables the ability to run aggregation pipelines D) Forces all reads to go to the primary shard only Answer: B Explanation: Disabling the balancer halts the automatic redistribution of chunks, leaving the current distribution unchanged. Question 48. Which aggregation stage would you use to write the result of a pipeline back into an existing collection named summary? A) $out B) $merge C) $replaceRoot D) $addFields Answer: B (or A) but we choose $merge for existing collection
C) db.users.createIndex({username:1}) D) db.users.indexes({username:1}) Answer: C Explanation: createIndex with {username:1} creates an ascending index; ensureIndex is deprecated. Question 52. When using a compound index {a:1, b:1}, which query can make use of the index for both fields? A) {b:5, a:10} B) {a:10} C) {a:10, b:5} D) {c:3} Answer: C Explanation: The query must follow the index order; specifying both a and b in the same order allows full index utilization. Question 53. Which statement about a “partial index” is true? A) It indexes every document in the collection B) It indexes only documents that match a filter expression, reducing index size C) It automatically expires after 30 days D) It can only be created on hashed fields Answer: B Explanation: A partial index includes only documents satisfying the given filter, making the index smaller and faster to maintain. Question 54. In an aggregation pipeline, which stage would you use to limit the number of documents returned to 5 after sorting?
A) $limit:5 placed before $sort B) $skip:5 after $sort C) $sort followed by $limit:5 D) $group with $push accumulator Answer: C Explanation: Sorting first ensures the top 5 documents are the highest/lowest according to the sort order; then $limit restricts the output. Question 55. Which of the following is NOT a valid read concern level? A) local B) majority C) linearizable D) durable Answer: D Explanation: durable is not a read concern; valid levels include local, majority, linearizable, and available. Question 56. What does the oplog contain in a replica set? A) Configuration settings for each member B) A log of all write operations that have been applied to the primary C) Authentication credentials for users D) Index definitions for all collections Answer: B Explanation: The oplog records every write operation on the primary, allowing secondaries to replicate those changes.