
































































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
A series of questions and answers related to the mongodb certified developer associate exam, focusing on key concepts such as schema design, query operators, aggregation pipelines, and sharding. It covers topics like embedding vs. Referencing, indexing strategies, and the use of operators like $ne, $exists, $push, and $inc. The document also explores aggregation stages like $match, $project, and $group, along with operators like $sum, $lookup, and $cond. Additionally, it addresses sharding concepts, including shard keys and chunk migration, providing a comprehensive overview of essential mongodb development topics. This material is useful for students and professionals preparing for mongodb certification or seeking to deepen their understanding of mongodb development practices. The questions cover a wide range of topics, from basic query operations to advanced aggregation techniques, making it a valuable resource for anyone working with mongodb.
Typology: Exams
1 / 72
This page cannot be seen from the preview
Don't miss anything!

































































Question 1. What is a primary advantage of using a document model over a relational model in MongoDB? A) Enforces strict schema validation B) Facilitates flexible schema design and faster read/write operations for certain use cases C) Supports complex joins natively D) Ensures data normalization Answer: B Explanation: The document model allows for flexible schemas and can lead to faster read/write operations, especially for hierarchical or nested data, unlike relational models that enforce strict schemas and rely on joins. Question 2. When designing schemas for one-to-many relationships, which approach is typically preferred in MongoDB? A) Embedding related documents within a parent document B) Using separate collections with references C) Normalizing data into multiple tables D) Using foreign key constraints Answer: A Explanation: Embedding related documents is preferred for one-to-many relationships when the embedded data is frequently accessed together, providing faster reads and atomic operations. Question 3. Which schema design pattern is suitable for representing hierarchical data such as organizational charts? A) Atomicity pattern B) Extended Reference pattern C) Tree Structure pattern D) Polymorphic Schemas Answer: C Explanation: The Tree Structure pattern represents hierarchical data efficiently, enabling parent-child relationships to be modeled within documents or via references.
Question 4. What is a key consideration when designing schemas to handle large data growth in MongoDB? A) Always embedding data B) Creating compound indexes on all fields C) Balancing embedding and referencing to optimize performance and scalability D) Using only single-field indexes Answer: C Explanation: Balancing embedding and referencing helps optimize performance, manage data growth, and prevent document size limits, especially as data volume increases. Question 5. Which insert operation is used to insert multiple documents into a collection at once? A) insertOne B) insertMany C) save D) addDocuments Answer: B Explanation: insertMany allows inserting multiple documents in a single operation, improving efficiency over multiple insertOne calls. Question 6. Which operator is used to find documents where a field is not equal to a specified value? A) $ne B) $eq C) $not D) $nin Answer: A Explanation: $ne (not equal) finds documents where the field's value is not equal to the specified value. Question 7. How does the $exists operator function in MongoDB queries? A) Checks if a field is of a specific type B) Checks if a field exists or not
Question 11. What is the role of write concern in MongoDB? A) Defines the durability guarantees for write operations B) Controls the speed of reads C) Manages user authentication D) Sets the cache size Answer: A Explanation: Write concern specifies the level of acknowledgment requested from MongoDB for write operations, affecting durability and consistency. Question 12. When creating an index on a field with multiple array values, which index type is used? A) Single field index B) Compound index C) Multikey index D) Text index Answer: C Explanation: Multikey indexes are automatically created on fields containing arrays, indexing each element for efficient querying. Question 13. What is the purpose of the explain() method in MongoDB? A) To execute a query B) To analyze query performance and index usage C) To modify the query plan D) To optimize query speed Answer: B Explanation: explain() provides details about how MongoDB executes a query, including index usage and performance metrics. Question 14. Which aggregation stage is used to filter documents within an aggregation pipeline? A) $match
B) $project C) $group D) $sort Answer: A Explanation: $match filters documents based on specified criteria, similar to a WHERE clause in SQL. Question 15. In the aggregation pipeline, which stage is used to reshape documents by adding, removing, or renaming fields? A) $match B) $project C) $group D) $sort Answer: B Explanation: $project modifies the shape of documents, allowing fields to be added, removed, or renamed. Question 16. How does the $group stage function in aggregation? A) Filters documents B) Groups documents by a specified key and applies aggregations C) Sorts documents D) Limits the number of documents Answer: B Explanation: $group aggregates documents based on a specified key and computes summary statistics using accumulator expressions. Question 17. Which aggregation operator computes the total sum of a field across grouped documents? A) $avg B) $min C) $max D) $sum
A) Performs conditional branching B) Filters documents C) Projects specific fields D) Groups documents Answer: A Explanation: $cond evaluates a boolean expression and returns different values based on the condition, enabling conditional logic. Question 22. Which expression is used to find the intersection of two sets in MongoDB aggregation? A) $setUnion B) $setIntersection C) $setDifference D) $setIsSubset Answer: B Explanation: $setIntersection returns the common elements between two sets. Question 23. What is the primary purpose of sharding in MongoDB? A) To ensure data consistency B) To enable horizontal scaling for large datasets C) To enforce schema constraints D) To improve data security Answer: B Explanation: Sharding distributes data across multiple servers, enabling horizontal scaling for large datasets and high throughput. Question 24. Which component in a sharded cluster routes client requests to the appropriate shard? A) Config server B) mongos C) Replica set
D) Balancer Answer: B Explanation: mongos acts as a query router, directing requests to the correct shard based on the shard key. Question 25. When choosing a shard key, which factor is most critical? A) Low cardinality B) Monotonic change C) High cardinality and even distribution D) Static value Answer: C Explanation: A good shard key has high cardinality and distributes data evenly across shards to avoid hotspots and ensure balanced load. Question 26. What is chunk migration in sharding? A) Transferring data from one replica set to another B) Moving chunks of data between shards to balance data distribution C) Exporting data to external storage D) Backing up shard data Answer: B Explanation: Chunk migration involves moving data chunks between shards to maintain balanced data distribution as data grows. Question 27. Which operation allows writing aggregation results directly into a new collection? A) $out B) $merge C) Both $out and $merge D) $lookup Answer: C
A) To monitor real-time data changes B) To perform bulk insert operations C) To optimize query performance D) To manage user privileges Answer: A Explanation: Change streams enable applications to listen for real-time changes in collections or databases. Question 32. Which filtering condition is used to resume a change stream after an interruption? A) resumeAfter B) startAtOperationTime C) initialResumeToken D) resumeToken Answer: D Explanation: The resumeToken allows a change stream to resume from the last seen event after an interruption. Question 33. When storing large files in MongoDB, which feature should be used? A) GridFS B) BLOB storage C) External file storage D) Document embedding Answer: A Explanation: GridFS is designed for storing and retrieving large files exceeding the document size limit by splitting files into chunks. Question 34. What collections does GridFS use internally to store files? A) fs.files and fs.chunks B) files and chunks C) large_files and file_chunks
D) gridfs_files and gridfs_chunks Answer: A Explanation: GridFS uses the fs.files collection for file metadata and fs.chunks for file data chunks. Question 35. Which authentication mechanism in MongoDB is based on a challenge-response mechanism? A) SCRAM-SHA- 1 B) LDAP C) Kerberos D) LDAP with SASL Answer: A Explanation: SCRAM-SHA-1 (and SCRAM-SHA-256) are challenge-response authentication mechanisms used in MongoDB. Question 36. Which role-based access control (RBAC) feature allows creating custom roles? A) Built-in roles B) User-defined roles C) Privileges D) Custom role creation Answer: D Explanation: MongoDB allows administrators to create custom roles with specific privileges tailored to application needs. Question 37. Which command is used to dump a MongoDB database backup? A) mongodump B) mongorestore C) mongoexport D) mongoimport Answer: A
A) Single field index B) Compound index C) Text index D) Geospatial index Answer: C Explanation: Text indexes enable full-text search capabilities over string content in documents. Question 42. Which index type is optimized for geospatial queries? A) Text index B) Compound index C) Geospatial index D) Unique index Answer: C Explanation: Geospatial indexes support spatial queries like proximity, intersection, and containment. Question 43. How does a sparse index differ from a regular index? A) Indexes only documents with the indexed field present B) Indexes all documents regardless of field presence C) Enforces uniqueness D) Supports full-text search Answer: A Explanation: Sparse indexes only include documents that have the indexed field, saving space and improving performance when many documents lack that field. Question 44. What is a TTL index used for in MongoDB? A) Automatically removes documents after a certain period B) Ensures uniqueness C) Supports geospatial queries D) Improves write performance
Answer: A Explanation: TTL (Time To Live) indexes automatically delete documents after a specified age, useful for expiring data like logs. Question 45. Which method is used to analyze query execution plans in MongoDB? A) explain() B) plan() C) analyze() D) profile() Answer: A Explanation: explain() provides detailed execution plans, helping optimize queries and indexes. Question 46. Which aggregation operator can be used to perform a left outer join between collections? A) $lookup B) $join C) $merge D) $combine Answer: A Explanation: $lookup facilitates joining data from other collections, similar to a left outer join in SQL. Question 47. Which aggregation stage is used to remove specific fields from documents? A) $unset B) $project C) $match D) $group Answer: A Explanation: $unset removes specified fields from documents in an aggregation pipeline. Question 48. How does the $set stage in aggregation differ from $addFields?
Answer: A Explanation: Multi-document transactions require replica sets and the WiredTiger storage engine to provide ACID guarantees across multiple documents. Question 52. In which scenario are multi-document transactions particularly useful? A) When multiple related updates need to be atomic B) For single-document updates only C) For read-only queries D) For creating indexes Answer: A Explanation: Multi-document transactions ensure that related multiple updates either all succeed or all fail, maintaining data integrity. Question 53. Which feature allows applications to listen for changes in real-time in MongoDB? A) Change streams B) Triggers C) Polling D) Notifications Answer: A Explanation: Change streams allow applications to receive real-time notifications about database changes. Question 54. What is required to open a change stream on a collection? A) MongoDB replica set or sharded cluster B) Only standalone server C) Specific index D) A special user role Answer: A Explanation: Change streams require a replica set or sharded cluster to function, as they rely on the oplog.
Question 55. Which security protocol ensures data in transit is encrypted in MongoDB? A) TLS/SSL B) SSH C) VPN D) IPsec Answer: A Explanation: TLS/SSL encrypts data transmitted between clients and servers, ensuring confidentiality. Question 56. How does enabling authentication affect MongoDB? A) Requires users to provide credentials to access data B) Disables access control C) Enables automatic data encryption D) Improves query performance Answer: A Explanation: Enabling authentication enforces user credential verification for access control. Question 57. Which command is used to start the MongoDB server? A) mongod B) mongo C) mongosh D) mongorestore Answer: A Explanation: mongod starts the MongoDB server process, hosting the database instances. Question 58. Which command is used to connect to a MongoDB server interactively? A) mongo B) mongod C) mongosh
Question 62. Which index property can improve performance for sparse data but may exclude documents lacking the indexed field? A) Sparse B) Unique C) TTL D) Multikey Answer: A Explanation: Sparse indexes only include documents with the indexed field, optimizing storage and performance for sparse data. Question 63. How does a unique index enforce data integrity? A) Prevents duplicate values in the indexed field B) Ensures data is sorted C) Supports full-text search D) Speeds up queries Answer: A Explanation: Unique indexes prevent duplicate entries in the index key, ensuring data integrity for that field. Question 64. Which command exports data from a collection to a JSON or CSV file? A) mongoexport B) mongodump C) mongorestore D) mongoimport Answer: A Explanation: mongoexport exports data from MongoDB to external files in JSON or CSV format. Question 65. What does the db.collection.drop() command do? A) Deletes the entire collection and its data
B) Removes all documents but keeps the collection C) Truncates the collection D) Renames the collection Answer: A Explanation: drop() deletes the collection and all its data permanently. Question 66. Which MongoDB utility is used for restoring data from a dump? A) mongorestore B) mongodump C) mongoimport D) mongoexport Answer: A Explanation: mongorestore restores data from backups created by mongodump. Question 67. Which MongoDB command provides the current replica set status? A) rs.status() B) db.serverStatus() C) rs.info() D) db.replSetGetStatus() Answer: D Explanation: db.replSetGetStatus() provides detailed status information about the replica set. Question 68. What is the primary purpose of the arbiter in a replica set? A) To vote in elections but not hold data B) To store a copy of the data C) To handle read operations D) To serve as a primary node Answer: A Explanation: An arbiter votes in elections to help determine the primary but does not store data.