MongoDB Associate Developer Exam — Questions and Answers
Question 1: What does the hint() cursor method do in MongoDB?
- Hints at which documents will be returned
- Forces MongoDB to use a specific index for the query (Correct answer)
- Adds hints to the query explanation
- Provides query optimization hints to developers
Correct answer: Forces MongoDB to use a specific index for the query
hint() overrides MongoDB's query optimizer and forces use of the specified index, which can be specified by name or key pattern.
Question 2: What is MongoDB's Encrypted Storage Engine used for?
- Encrypting backup files automatically
- Encrypting data files at rest using AES-256 encryption (Correct answer)
- Encrypting network traffic between shards
- Encrypting field values within documents
Correct answer: Encrypting data files at rest using AES-256 encryption
MongoDB Enterprise's encrypted storage engine encrypts all data files at rest using AES-256, protecting data if physical storage is compromised.
Question 3: What is a sparse index in MongoDB?
- An index that only includes documents where the indexed field exists (Correct answer)
- An index with gaps between entries
- An index on sparsely populated collections
- A partial index on every other document
Correct answer: An index that only includes documents where the indexed field exists
A sparse index only contains entries for documents that have the indexed field, skipping documents where the field is absent.
Question 4: What are the three main components of a MongoDB sharded cluster?
- Primary, secondary, arbiter
- Router, coordinator, and replica
- Balancer, indexer, and data node
- Mongos, config servers, and shards (Correct answer)
Correct answer: Mongos, config servers, and shards
A MongoDB sharded cluster consists of: (1) mongos — the query router that clients connect to; (2) config servers — store cluster metadata and chunk distribution; and (3) shards — each shard is a replica set holding a subset of the sharded data.
Question 5: What does the findOne() method return when no matching document is found?
- An empty object {}
- null (Correct answer)
- undefined
- An empty array []
Correct answer: null
findOne() returns null when no document matches the specified query filter.
Question 6: What is a MongoDB arbiter in a replica set?
- A delayed secondary used for backup purposes
- A hidden member that is invisible to client connections
- A read-only secondary that serves analytics queries
- A member that holds no data but participates in elections to break ties (Correct answer)
Correct answer: A member that holds no data but participates in elections to break ties
An arbiter holds no data and cannot become primary. Its sole purpose is to vote in elections to break ties when an even number of data-bearing members are present. Arbiters use minimal resources but introduce a potential single point of failure.
Question 7: What is Atlas Data Federation?
- Federating multiple Atlas organizations under one billing account
- Querying and combining data from Atlas clusters, S3 buckets, and Atlas Data Lake using MQL or SQL (Correct answer)
- Federating identity providers for Atlas authentication
- Syncing data between Atlas clusters across different cloud providers
Correct answer: Querying and combining data from Atlas clusters, S3 buckets, and Atlas Data Lake using MQL or SQL
Atlas Data Federation enables querying data across multiple sources — Atlas clusters, AWS S3, Azure Blob Storage, HTTP endpoints, and Atlas Online Archive — using MongoDB Query Language or SQL. Results from disparate sources are unified without ETL pipelines.
Question 8: Which stage sorts the documents in the aggregation pipeline?
- $sort (Correct answer)
- $order
- $arrange
- $rank
Correct answer: $sort
$sort reorders pipeline documents according to specified fields, using 1 for ascending and -1 for descending.
Question 9: Which MongoDB query operator matches values that are greater than or equal to a specified value?
- $goe
- $gte (Correct answer)
- $ge
- $gt
Correct answer: $gte
$gte (greater than or equal) matches documents where the field value is greater than or equal to the specified value.
Question 10: $push is an array operator that adds a key to an array at the ______.
- As per key value
- Start
- Specified position
- End (Correct answer)
Correct answer: End
The `$push` operator in MongoDB is used to append a specified value to an array field within a document. When `$push` is applied, the new element is added to the end of the existing array. This makes it a straightforward way to grow an array by adding new items sequentially.
Question 11: What is a shard key in MongoDB sharding?
- A unique index on every shard
- A field or combination of fields that determines how documents are distributed across shards (Correct answer)
- An encryption key for shard-level data security
- A password for shard authentication
Correct answer: A field or combination of fields that determines how documents are distributed across shards
The shard key is a field (or compound fields) whose values determine which shard stores each document. MongoDB divides the shard key value range into chunks and distributes these chunks across shards. Choosing the right shard key is critical for balanced distribution and query efficiency.
Question 12: Which operator is used to match documents where an array field contains all of the specified elements?
- $elemMatch
- $all (Correct answer)
- $in
- $size
Correct answer: $all
$all matches arrays that contain every element in the specified list, regardless of order.
Question 13: What does ACID stand for in the context of database transactions?
- Associative, Consistent, Incremental, Distributed
- Atomic, Consistent, Isolated, Durable (Correct answer)
- Atomic, Cached, Isolated, Dynamic
- Automated, Concurrent, Indexed, Distributed
Correct answer: Atomic, Consistent, Isolated, Durable
ACID stands for Atomicity (all operations succeed or all are rolled back), Consistency (data moves from one valid state to another), Isolation (concurrent transactions don't interfere), and Durability (committed transactions persist even after system failure).
Question 14: What is the 'snapshot' isolation level provided by MongoDB transactions?
- Reads see uncommitted data from other concurrent transactions
- All reads within the transaction see a consistent snapshot of data as it existed at the transaction's start time (Correct answer)
- Reads are locked and block all writes until the transaction commits
- Each read within the transaction sees the most recent committed data
Correct answer: All reads within the transaction see a consistent snapshot of data as it existed at the transaction's start time
Snapshot isolation ensures all read operations within a transaction see a consistent view of the data as it existed at the logical transaction start time. This means the transaction is isolated from any committed or uncommitted changes made by concurrent transactions during its execution.
Question 15: What is MongoDB Atlas?
- An on-premises MongoDB deployment tool
- A MongoDB backup and restore utility
- MongoDB's fully managed cloud database service available on AWS, Azure, and GCP (Correct answer)
- An open-source MongoDB monitoring dashboard
Correct answer: MongoDB's fully managed cloud database service available on AWS, Azure, and GCP
MongoDB Atlas is the official fully managed cloud database service from MongoDB, Inc. It automates provisioning, setup, monitoring, backups, and patching of MongoDB clusters across AWS, Microsoft Azure, and Google Cloud Platform, allowing developers to focus on application development.
Question 16: In a wrapped query, ______ is a useful option that sets the maximum number of documents to verify for a given query.
- max
- scanmax
- maxscan (Correct answer)
- scan
Correct answer: maxscan
The `maxscan` option in MongoDB queries limits the maximum number of documents that the database will scan on disk to fulfill a query. This is particularly useful for preventing long-running or inefficient queries that might scan an excessive number of documents, especially when an optimal index is not available. It helps control resource usage and improve query performance by setting an upper bound on the scan effort.
Question 17: What happens to a replica set member whose oplog window is exceeded by replication lag?
- It becomes an arbiter temporarily
- It triggers an immediate election
- It automatically increases its oplog size
- It enters RECOVERING state and must be resynced from another member (Correct answer)
Correct answer: It enters RECOVERING state and must be resynced from another member
If a secondary falls too far behind and the primary's oldest oplog entry is newer than the secondary's last applied operation, the secondary can no longer replicate incrementally. It enters RECOVERING state and requires a full resync (initial sync) from a healthy member.
Question 18: When modeling a many-to-many relationship in MongoDB, which approach avoids duplication while keeping queries efficient?
- Use a separate database for each side of the relationship
- Denormalize all data into a single document
- Use an intermediate linking collection or store arrays of references on one or both sides (Correct answer)
- Embed all related documents on both sides
Correct answer: Use an intermediate linking collection or store arrays of references on one or both sides
For many-to-many relationships, a common approach is to store arrays of ObjectId references in documents on one or both sides. For complex cases, an intermediate collection (junction collection) explicitly models the relationship and can carry relationship-specific attributes.
Question 19: What happens when you shard a collection in MongoDB that already has data?
- The operation fails; sharding must be done on empty collections
- MongoDB creates an initial chunk and begins distributing data during subsequent balancer runs (Correct answer)
- Existing documents are immediately distributed to all shards
- All existing documents are moved to shard 0
Correct answer: MongoDB creates an initial chunk and begins distributing data during subsequent balancer runs
When you enable sharding on an existing collection, MongoDB creates an initial chunk containing all existing documents on the primary shard. The balancer then gradually migrates chunks to other shards over time. Initial sync doesn't happen instantaneously.
Question 20: What happens to a MongoDB transaction if commitTransaction() is not called before the session times out?
- The transaction is committed automatically
- The transaction is saved as a pending transaction
- The transaction is rolled back and all changes are discarded (Correct answer)
- An error is thrown and the application must retry
Correct answer: The transaction is rolled back and all changes are discarded
If a transaction is not committed before the session or transaction timeout (default 60 seconds), MongoDB automatically aborts and rolls back the transaction. All write operations within the transaction are discarded as if they never occurred.
Question 21: What is a transient transaction error in MongoDB and how should it be handled?
- An error that permanently invalidates the transaction; application must abort
- An error that commits a partial transaction
- An error caused by schema validation failure within the transaction
- A temporary error (e.g., write conflict or network issue) that can be resolved by retrying the entire transaction (Correct answer)
Correct answer: A temporary error (e.g., write conflict or network issue) that can be resolved by retrying the entire transaction
Transient transaction errors (ErrorLabel: 'TransientTransactionError') indicate temporary conditions like write conflicts or network issues. The application should catch these errors and retry the entire transaction from the beginning, as the original transaction was rolled back.
Question 22: Which write concern provides the lowest durability but the highest write throughput in MongoDB?
- { w: 1 }
- { w: 0 } (Correct answer)
- { w: 'all' }
- { w: 'majority' }
Correct answer: { w: 0 }
{ w: 0 } is 'fire and forget' — MongoDB does not wait for any acknowledgment before returning to the client. This gives maximum throughput but offers no durability guarantee. The write may be lost if the server crashes before it is persisted.
Question 23: Which MongoDB query operator matches documents where a field value is greater than a specified value?
- $gt (Correct answer)
- $lte
- $gte
- $lt
Correct answer: $gt
$gt (greater than) selects documents where the field value is strictly greater than the specified value.
Question 24: What is a covered query in MongoDB?
- A query that covers all documents in a collection
- A query with full-text search coverage
- A query that can be satisfied entirely using an index without accessing documents (Correct answer)
- A query protected by access control
Correct answer: A query that can be satisfied entirely using an index without accessing documents
A covered query is fulfilled entirely by the index, meaning MongoDB never needs to read actual documents, resulting in very high performance.
Question 25: What is a key indicator that you should move from embedding to referencing in an existing schema?
- Query response times are under 1 ms
- The database is using WiredTiger storage engine
- Embedded arrays are growing unboundedly, risking the 16 MB document limit (Correct answer)
- The collection has fewer than 1,000 documents
Correct answer: Embedded arrays are growing unboundedly, risking the 16 MB document limit
When embedded arrays grow without bound — e.g., an activity log embedded in a user document — the document can eventually exceed the 16 MB BSON limit. This is a clear signal to switch to referencing, storing related records in a separate collection.
Question 26: What is a partial index in MongoDB?
- An index covering only part of a field's value
- A degraded index after a hardware failure
- An incomplete index being built in the background
- An index that only includes documents meeting a specified filter expression (Correct answer)
Correct answer: An index that only includes documents meeting a specified filter expression
A partial index indexes only documents that satisfy a specified filter, resulting in smaller, more efficient indexes for common query patterns.
Question 27: What is the difference between vertical scaling and horizontal scaling in the context of MongoDB?
- Vertical scaling increases CPU/RAM on existing servers; horizontal scaling adds more servers (shards) to distribute data (Correct answer)
- Vertical scaling adds more servers; horizontal scaling adds more CPU/RAM to existing servers
- There is no difference; they are synonyms in MongoDB
- Vertical scaling is only for reads; horizontal scaling is only for writes
Correct answer: Vertical scaling increases CPU/RAM on existing servers; horizontal scaling adds more servers (shards) to distribute data
Vertical scaling (scaling up) means adding more resources (CPU, RAM, storage) to a single server. Horizontal scaling (scaling out) means adding more servers. MongoDB sharding is a horizontal scaling strategy — adding shards distributes data and workload across multiple servers.
Question 28: The command to get a backup of a point-in-time data view is ____.
- sync
- mangodump
- dump
- fsync (Correct answer)
Correct answer: fsync
The `fsync` command in MongoDB, specifically `db.fsyncLock()`, is used to lock the database and flush all pending writes to disk. This action creates a consistent point-in-time snapshot of the data files, which can then be safely copied using file system tools for backup purposes. After copying, `db.fsyncUnlock()` releases the lock, allowing normal operations to resume.
Question 29: What does the $elemMatch operator do when used in a MongoDB query on an array field?
- Returns all elements from the matching array
- Matches documents where at least one array element satisfies all specified conditions (Correct answer)
- Counts the number of matching array elements
- Returns only the matching elements from the array
Correct answer: Matches documents where at least one array element satisfies all specified conditions
$elemMatch matches documents where at least one array element meets all conditions specified within the operator.
Question 30: Which MongoDB feature enforces that fields meet specific data type requirements?
- Collection constraints
- Schema validation with $jsonSchema (Correct answer)
- Strict mode
- Type checking middleware
Correct answer: Schema validation with $jsonSchema
$jsonSchema in collection validation rules allows specifying required fields, allowed types, value ranges, and other constraints enforced on write operations.
Question 31: Which MongoDB operator enables full-text search on fields that have a text index?
- $like
- $search
- $text (Correct answer)
- $regex
Correct answer: $text
$text performs a text search on the content of fields indexed with a text index.
Question 32: What happens to indexes when a MongoDB collection is dropped?
- Indexes are preserved for the new collection
- Indexes are moved to a system collection
- Indexes must be manually dropped before dropping the collection
- All indexes on the collection are automatically deleted (Correct answer)
Correct answer: All indexes on the collection are automatically deleted
When a collection is dropped, all its indexes are automatically removed along with the collection data.
Question 33: How do you limit the number of documents returned by a MongoDB query?
- .max(n)
- .limit(n) (Correct answer)
- .top(n)
- .restrict(n)
Correct answer: .limit(n)
.limit(n) restricts the cursor to return only the first n documents from the result set.
Question 34: What backup capability does Atlas provide with Continuous Cloud Backup?
- Hourly snapshots only, retained for 7 days
- Point-in-time recovery using continuous oplog backup, allowing restoration to any point within the retention window (Correct answer)
- Backups that must be manually triggered by the database administrator
- Full cluster backup every 24 hours with no point-in-time option
Correct answer: Point-in-time recovery using continuous oplog backup, allowing restoration to any point within the retention window
Atlas Continuous Cloud Backup captures continuous oplog data in addition to periodic snapshots. This enables point-in-time restore (PITR) to any second within the configured retention window (up to 35 days). It provides recovery options for accidental writes, deletions, or application bugs.
Question 35: What does Atlas Online Archive do?
- Copies Atlas cluster snapshots to long-term cold storage
- Permanently deletes data older than a specified date
- Archives Atlas configuration and schema history
- Automatically moves infrequently accessed data from Atlas clusters to cost-effective cloud object storage (Correct answer)
Correct answer: Automatically moves infrequently accessed data from Atlas clusters to cost-effective cloud object storage
Atlas Online Archive automatically tiers cold data from your Atlas cluster to MongoDB-managed cloud object storage based on date or custom criteria. Archived data remains queryable via Atlas Data Federation, reducing cluster storage costs while maintaining accessibility.
Question 36: What is index selectivity in MongoDB performance tuning?
- The number of fields included in a compound index
- How effectively an index narrows down the candidate documents (Correct answer)
- How selectively indexes are created per collection
- The ability to select which index to use manually
Correct answer: How effectively an index narrows down the candidate documents
Index selectivity measures how much an index reduces the number of documents that need to be examined, with higher selectivity meaning fewer documents examined.
Question 37: What problem does the Computed Pattern solve in MongoDB?
- It computes index statistics in real time
- It computes shard keys automatically
- It pre-computes and stores results that are expensive to calculate on every read (Correct answer)
- It resolves schema conflicts between collections
Correct answer: It pre-computes and stores results that are expensive to calculate on every read
The Computed Pattern pre-calculates expensive values (e.g., totals, averages, counts) and stores them in the document. Instead of running costly aggregations on every read, the application reads the pre-computed value and updates it periodically or on write.
Question 38: Which operator selects documents where a field value matches any value in a specified array?
- $in (Correct answer)
- $exists
- $elemMatch
- $all
Correct answer: $in
$in matches documents where the field value is equal to any value in the specified array.
Question 39: What is the ESR rule for compound index design in MongoDB?
- Embedded, Scalar, Reference — document design patterns
- Equality, Sort, Range — order fields in this sequence (Correct answer)
- Efficient, Selective, Relevant — criteria for index creation
- Exact, Sparse, Range — use these index types together
Correct answer: Equality, Sort, Range — order fields in this sequence
The ESR rule states that in a compound index, place Equality fields first, Sort fields second, and Range fields last for optimal query performance.
Question 40: What is the purpose of schema versioning in MongoDB?
- To lock the schema for production deployments
- To automatically upgrade field types on insert
- To version control the database binary
- To allow gradual migration of documents to a new schema without downtime (Correct answer)
Correct answer: To allow gradual migration of documents to a new schema without downtime
The Schema Versioning Pattern adds a 'schema_version' field to documents. Application code handles multiple versions simultaneously, allowing lazy migration — old documents are updated to the new schema when they are next read or written, avoiding a big-bang migration.
Question 41: What does the $count stage return in an aggregation pipeline?
- The count per group
- A single document with the count of documents passed to it (Correct answer)
- A running total of documents
- An array of all document IDs
Correct answer: A single document with the count of documents passed to it
$count outputs a single document containing a field with the count of documents that entered the stage.
Question 42: When should you prefer referencing over embedding in MongoDB?
- When related data is large, changes frequently, or is accessed independently (Correct answer)
- When using a single-node replica set
- When you need to avoid all multi-document reads
- When data is always accessed together and fits within 16 MB
Correct answer: When related data is large, changes frequently, or is accessed independently
Referencing is preferred when related data is large (risking document size limits), changes frequently (avoiding expensive rewrites of the parent document), or is frequently accessed independently. It keeps documents manageable but requires additional queries or $lookup.
Question 43: What is the Outlier Pattern in MongoDB schema design used for?
- Separating outlier queries to a different collection
- Managing a small number of documents that have many more relationships than typical documents (Correct answer)
- Handling documents that exceed normal field counts
- Flagging data quality issues
Correct answer: Managing a small number of documents that have many more relationships than typical documents
The Outlier Pattern addresses the situation where a few documents have far more related items than typical, such as a popular author with thousands of books. A flag field identifies outliers, and overflow data is stored in separate documents to avoid document size limits.
Question 44: Which MongoDB query operator matches documents where a field value falls within a specified range using two boundary values?
- $range
- Combining $gte and $lte operators (Correct answer)
- $between
- $within
Correct answer: Combining $gte and $lte operators
MongoDB uses a combination of $gte and $lte within the same field query to match a range of values.
Question 45: Which method creates an index on a MongoDB collection?
- collection.newIndex()
- collection.createIndex() (Correct answer)
- collection.buildIndex()
- collection.addIndex()
Correct answer: collection.createIndex()
createIndex() creates an index on the specified field(s) with the given options, or returns the existing index name if it already exists.
Question 46: Which index option ensures no two documents can have the same value for the indexed field?
- { exclusive: true }
- { single: true }
- { unique: true } (Correct answer)
- { distinct: true }
Correct answer: { unique: true }
Setting unique: true when creating an index causes MongoDB to reject any insert or update that would create a duplicate value for the indexed field.
Question 47: What does the allowDiskUse option do in the aggregate() method?
- Allows writing aggregation results to disk
- Allows reading data from disk archives
- Permits aggregation stages to use temporary files when memory limit is exceeded (Correct answer)
- Enables disk-based indexing during aggregation
Correct answer: Permits aggregation stages to use temporary files when memory limit is exceeded
allowDiskUse: true allows aggregation stages to write temporary files to disk when the 100MB memory limit per stage is exceeded.
Question 48: Which of the following statements concerning sharding is correct?
- Sharding is enabled at the database level
- Because the documents are spread across multiple mongod instances, sorting is not possible in a sharded environment.
- Once a shard key is put up, we can't alter it directly or automatically. (Correct answer)
- When you create a sharded key, it also builds an index on the collection that uses that key.
Correct answer: Once a shard key is put up, we can't alter it directly or automatically.
The shard key is a critical component of a sharded cluster, determining how data is distributed across shards. Once a shard key is defined for a collection, it cannot be directly changed or modified. Altering a shard key typically requires a complex migration process, often involving dumping the data, dropping the collection, and re-inserting it with a new shard key.
Question 49: What does Atlas Global Clusters enable?
- Running queries globally across all Atlas organizations
- Zone-based data distribution across geographic regions for low-latency local reads and data sovereignty compliance (Correct answer)
- Automating index creation globally across all collections
- Deploying a cluster on all three cloud providers simultaneously
Correct answer: Zone-based data distribution across geographic regions for low-latency local reads and data sovereignty compliance
Atlas Global Clusters use MongoDB's zone sharding to distribute data across geographic regions. You define location-based zones so data is stored close to users for low-latency reads, and to comply with data residency regulations requiring data to remain in specific regions.
Question 50: Which of the following best describes a one-to-zillions relationship in MongoDB schema design?
- A many-to-many relationship handled by an intermediate collection
- A relationship where millions of child documents point to one parent, making embedding impractical (Correct answer)
- A self-referencing document structure
- A parent document with a small embedded array
Correct answer: A relationship where millions of child documents point to one parent, making embedding impractical
One-to-zillions describes relationships where the child side is unbounded and potentially enormous (e.g., log entries for a server). Embedding is impossible due to document size limits. Instead, each child document stores a reference to the parent — the reverse of typical embedding.
Question 51: What is the default transaction timeout limit in MongoDB?
- 120 seconds
- 30 seconds
- 300 seconds
- 60 seconds (Correct answer)
Correct answer: 60 seconds
MongoDB transactions have a default timeout of 60 seconds (configurable via transactionLifetimeLimitSeconds). Transactions running longer than this limit are automatically aborted. Long-running transactions should be avoided as they hold locks and impact performance.
Question 52: Which read concern is required to read the latest majority-committed data within a MongoDB transaction?
- snapshot (Correct answer)
- available
- majority
- local
Correct answer: snapshot
Transactions default to 'snapshot' read concern, which provides a consistent snapshot of the data as of the transaction's start time. 'snapshot' read concern ensures that all reads within a transaction see the same consistent view of the data.
MongoDB Associate Developer Exam
The MongoDB Associate Developer Exam validates core MongoDB development skills including CRUD operations, indexing strategies, schema design, and application integration using MongoDB drivers. It is the primary entry-level certification for developers building applications with MongoDB.
Exam Rules
- You can skip questions and return to them later
- Flag questions for review before submitting
- No feedback shown until you submit the entire exam
- Unanswered questions count as wrong — answer everything
- 10 pretest questions are mixed in and don't affect your score
- Timer auto-submits when time runs out
- Your progress is auto-saved every 30 seconds