MongoDB C100DBA Practice Test Questions and Exam Dumps Part10 Q181-200

View Full MongoDB C100DBA Exam Dumps and Practice Test Dumps

 

Question 181

Which MongoDB option specifies the index to use for a query?

  1. forceIndex
  2. hint()
  3. useIndex()
  4. selectIndex()

Correct Answer: 2

Explanation:

The hint() method instructs MongoDB to use a particular index when executing a query. It can be useful when testing index behavior, troubleshooting query plans, or validating whether a specific index provides the expected execution characteristics. Administrators should use hints carefully because forcing an unsuitable index can degrade performance. Query plans may change as data distribution and indexes evolve, so permanent hints should be justified by measured workload behavior. DBAs can combine hint() with explain() to investigate how MongoDB executes a query and determine whether the selected index reduces unnecessary document or key examination.

Question 182

Which MongoDB query feature allows a query to use a specific index by name?

  1. indexName()
  2. force()
  3. hint()
  4. selectIndex()

Correct Answer: 3

Explanation:

MongoDB’s hint() functionality can identify an index by its name, allowing administrators to explicitly direct query planning toward that index. Index names are commonly generated from indexed fields unless a custom name is supplied during index creation. Using the name can be convenient when several indexes have similar structures or when administrators need precise control during testing. DBAs should verify that the named index exists before relying on it. Hints are primarily an optimization and troubleshooting mechanism, not a substitute for appropriate index design and workload analysis.

Question 183

Which MongoDB feature can provide cached query-plan information?

  1. Plan cache
  2. Query memory
  3. Cursor archive
  4. Index registry

Correct Answer: 1

Explanation:

MongoDB maintains query-plan cache information for eligible query shapes so that previously selected execution strategies can be reused when appropriate. This can reduce the overhead of repeatedly evaluating candidate plans for similar queries. The plan cache is associated with query shapes rather than individual literal values. Administrators investigating unexpected query performance can inspect or clear plan-cache information using supported database commands. DBAs should remember that cached plans may become less suitable as indexes, data distribution, or workload characteristics change, making plan-cache investigation useful during performance troubleshooting.

Question 184

Which query pattern is known as a covered query?

  1. Filter uses no index
  2. Query performs collection scan
  3. Results require full documents
  4. Index supplies filter and fields

Correct Answer: 4

Explanation:

A covered query is one where the index contains all fields required to evaluate the query and return the requested results, allowing MongoDB to avoid fetching the complete documents. Covered queries can reduce document examination and improve performance for suitable workloads. Whether a query is covered depends on both its filter and projection. Administrators should verify coverage using explain() rather than assuming that an index automatically provides it. DBAs designing high-volume read workloads can consider indexes that support both filtering and required returned fields when the additional index storage and maintenance cost is justified.

Question 185

Which MongoDB command clears cached query plans for a collection?

  1. planCacheClear
  2. clearQueryCache
  3. planCacheClear command
  4. resetPlanner

Correct Answer: 3

Explanation:

The planCacheClear command is used to clear cached query plans associated with a collection. It can be useful during query-performance troubleshooting when cached planning information is suspected of contributing to unexpected execution behavior. Clearing the cache causes MongoDB to reconsider plans as new queries are evaluated. Administrators should not treat cache clearing as a general performance fix because it can temporarily increase planning work. A DBA should first investigate indexes, query shapes, data distribution, and execution statistics before using plan-cache operations as part of a broader troubleshooting process.

Question 186

Which MongoDB method returns distinct values for a specified field?

  1. uniqueValues()
  2. distinct()
  3. different()
  4. fieldValues()

Correct Answer: 2

Explanation:

The distinct() method returns the unique values for a specified field across documents that satisfy an optional query filter. It is useful when applications need a set of different categories, statuses, identifiers, or other field values without retrieving complete documents. The operation can still require substantial processing on large datasets, particularly when efficient access paths are unavailable. DBAs should evaluate workload frequency and dataset size before placing distinct-value operations on heavily used application paths. Appropriate indexing and selective filtering can help reduce unnecessary examination for some workloads.

Question 187

Which MongoDB cursor method skips a specified number of results?

  1. offset()
  2. jump()
  3. skip()
  4. advance()

Correct Answer: 3

Explanation:

The skip() cursor method instructs MongoDB to skip a specified number of matching documents before returning results. It is commonly used with limit() for simple pagination. However, very large skip values can become inefficient because MongoDB may still need to process and advance through the skipped results. For high-volume datasets, range-based pagination using indexed fields can often avoid repeatedly scanning large offsets. DBAs should therefore evaluate the expected page depth and workload size before using large skip values in production applications.

Question 188

Which aggregation stage limits the number of documents passed forward?

  1. $limit
  2. $cap
  3. $restrict
  4. $top

Correct Answer: 1

Explanation:

The $limit aggregation stage restricts the number of documents that continue through the pipeline. It is particularly useful for top-result queries, pagination patterns, and reducing downstream processing. When $limit follows an appropriate $sort, MongoDB can produce a defined subset according to the requested ordering. Pipeline stage placement matters because limiting too early may remove documents that later stages would otherwise need. DBAs should design aggregation pipelines with filtering, sorting, and limiting in an order that preserves required semantics while minimizing unnecessary processing.

Question 189

Which aggregation stage removes unwanted fields from documents?

  1. $discard
  2. $project
  3. $removeFields
  4. $omitFields

Correct Answer: 2

Explanation:

The $project aggregation stage controls which fields are included or excluded from documents flowing through a pipeline. It can also create computed fields and reshape documents. By removing unnecessary fields early when appropriate, a pipeline may reduce the amount of data carried into later processing stages. However, administrators should ensure that fields required by subsequent stages are retained. $project is commonly used when aggregation output needs a specific structure rather than the complete original document. DBAs should also consider whether projection can be combined effectively with other pipeline stages for efficient processing.

Question 190

Which aggregation stage orders documents by specified fields?

  1. $arrange
  2. $order
  3. $sort
  4. $sequence

Correct Answer: 3

Explanation:

The $sort aggregation stage orders documents according to specified fields and sort directions. A value of 1 represents ascending order, while -1 represents descending order. Sorting can be resource-intensive when large datasets are involved, especially if no suitable index can support the operation. Administrators should inspect explain information and pipeline structure when optimizing large aggregation workloads. Combining selective filtering with appropriate indexing can reduce the number of documents that must be sorted. $sort is often paired with $limit when applications need only the highest- or lowest-ranked results.

Question 191

Which aggregation stage calculates the number of documents entering that stage?

  1. $total
  2. $count
  3. $quantity
  4. $documentCount

Correct Answer: 2

Explanation:

The $count aggregation stage produces a document containing the number of documents that reach that stage of the pipeline. It is useful for reporting, analytics, and filtered-result counting. Because only documents that survive earlier stages are counted, $match can be placed before $count when only a subset should contribute to the result. DBAs should understand the pipeline order because moving filtering stages can change both semantics and performance. For very large datasets, administrators should evaluate the cost of the preceding stages because the counting operation itself is only one part of the total workload.

Question 192

Which aggregation stage can add computed fields to pipeline documents?

  1. $set
  2. $calculate
  3. $compute
  4. $derive

Correct Answer: 1

Explanation:

The $set aggregation stage adds new fields or replaces existing fields in documents flowing through a pipeline. It is useful for creating calculated values, transforming fields, or preparing documents for later stages. $set is an alias for the aggregation behavior provided by $addFields, allowing administrators to choose terminology that fits the pipeline design. DBAs should ensure that expressions reference the correct field paths and data types. When building complex pipelines, placing transformations at an appropriate stage can prevent unnecessary processing of documents that could have been filtered earlier.

Question 193

Which aggregation stage combines documents from another collection?

  1. $combine
  2. $join
  3. $lookup
  4. $attach

Correct Answer: 3

Explanation:

The $lookup aggregation stage performs a left outer join with documents from another collection. It allows aggregation pipelines to enrich documents using related data stored separately. $lookup can use straightforward equality matching or more advanced pipeline-based forms depending on the use case. Administrators should consider indexing on the foreign collection’s matching field because inefficient joins can become expensive with large datasets. DBAs should also evaluate the number of documents involved and the resulting document size when designing cross-collection aggregation workloads.

Question 194

Which aggregation stage removes an entire field from pipeline documents?

  1. $erase
  2. $unset
  3. $deleteField
  4. $dropField

Correct Answer: 2

Explanation:

The $unset aggregation stage removes specified fields from documents as they move through a pipeline. It is useful when output documents should exclude sensitive, unnecessary, or intermediate fields created during earlier processing. $unset can be used to simplify aggregation results before they are returned or written elsewhere. Administrators should ensure that no later pipeline stage requires a field before removing it. This operation affects the documents flowing through the pipeline and does not automatically modify the original stored documents unless the pipeline subsequently uses a stage that writes results back to a collection.

Question 195

Which aggregation stage writes pipeline results into an existing or new collection?

  1. $write
  2. $output
  3. $out
  4. $store

Correct Answer: 3

Explanation:

The $out aggregation stage writes pipeline results to a specified collection. It is useful for materializing aggregation results, generating reporting collections, or transforming data into a separate stored representation. Because $out produces persistent collection data, administrators should carefully consider naming, permissions, existing collection behavior, and operational impact. It differs from returning aggregation results directly to the client because the pipeline output becomes stored database data. DBAs should test $out workflows carefully, particularly when large datasets or production collections are involved.

Question 196

Which MongoDB method replaces an entire matching document?

  1. replaceOne()
  2. overwriteOne()
  3. replaceDocument()
  4. swapOne()

Correct Answer: 1

Explanation:

The replaceOne() method replaces the contents of one document matching a filter with a replacement document. Unlike update operators such as $set, replacement operations replace the existing document body rather than modifying selected fields. The replacement document must satisfy MongoDB’s document rules and cannot arbitrarily preserve fields unless they are included in the replacement. Administrators should be especially careful with fields that must remain present, including application-managed metadata. replaceOne() is useful for complete document replacement workflows where the application has constructed the intended new document representation.

Question 197

Which MongoDB operation can insert a document when no match exists during an update?

  1. insertIfMissing
  2. upsert
  3. createOnFail
  4. mergeInsert

Correct Answer: 2

Explanation:

An upsert combines update behavior with conditional insertion. When an update operation uses upsert: true and no document matches the filter, MongoDB creates a new document based on the operation’s applicable update semantics. If a matching document exists, the update is applied instead. Upserts are useful for maintaining configuration records, counters, or application state without requiring a separate existence check. DBAs should design the filter carefully because an overly broad or non-unique filter can produce unexpected matching behavior. Appropriate indexes can also help make repeated upsert operations efficient.

Question 198

Which MongoDB method atomically finds and updates one document?

  1. updateAndFind()
  2. findThenUpdate()
  3. findOneAndUpdate()
  4. modifyOneAndReturn()

Correct Answer: 3

Explanation:

findOneAndUpdate() finds a single document matching a filter and applies an update operation as one database operation. It is useful when an application needs to modify a document while also obtaining the affected document according to the operation’s return settings. Options can control aspects such as sorting, upsert behavior, projection, and whether the returned document represents the previous or updated state. DBAs should ensure that the filter and update semantics match the intended concurrency behavior. Appropriate indexing can also improve the efficiency of locating the target document.

Question 199

Which MongoDB connection option controls the maximum number of pooled connections?

  1. maxPoolSize
  2. poolLimit
  3. connectionMaximum
  4. maxConnections

Correct Answer: 1

Explanation:

The maxPoolSize connection option controls the maximum number of connections that a MongoDB client maintains in a connection pool for a server. Connection pooling allows applications to reuse established connections rather than repeatedly creating new ones. Setting the maximum too low can cause requests to wait for available connections, while setting it unnecessarily high can increase server and client resource consumption. DBAs should size connection pools according to application concurrency, deployment topology, driver behavior, and server capacity. Monitoring connection usage helps identify whether pool settings are appropriate.

Question 200

Which MongoDB connection option limits how long a client waits to select a suitable server?

  1. connectTimeoutMS
  2. serverSelectionTimeoutMS
  3. socketTimeoutMS
  4. serverWaitMS

Correct Answer: 2

Explanation:

serverSelectionTimeoutMS specifies how long a MongoDB driver attempts to select a suitable server before reporting a server-selection error. It is important in deployments involving replica sets, failover, or multiple available server candidates. This setting is different from connectTimeoutMS, which concerns establishing a network connection, and socketTimeoutMS, which controls socket-level operation timing after connection. DBAs should configure server-selection behavior according to application availability requirements and deployment characteristics. Excessively short values can cause avoidable failures during transient topology changes or elections.