MongoDB C100DBA Practice Test Questions and Exam Dumps Part8 Q141-160

View Full MongoDB C100DBA Exam Dumps and Practice Test Dumps

 

Question 141

Which MongoDB command changes the current database context?

  1. use databaseName
  2. switch databaseName
  3. select databaseName
  4. change databaseName

Correct Answer: 1

Explanation:

The use command changes the current database context in the MongoDB shell. It does not create the database immediately; the database becomes persistent when data or another database object is created within it. Administrators frequently use this command before running collection, user, or database-level operations. Verifying the active database context is important because many shell commands operate against the currently selected database. Accidentally selecting the wrong database before executing administrative commands can produce unintended results. DBAs should therefore confirm the active context before performing destructive or security-related operations.

Question 142

Which command removes an individual document matching a filter?

  1. deleteOne()
  2. removeDocument()
  3. eraseOne()
  4. dropDocument()

Correct Answer: 1

Explanation:

deleteOne() removes a single document that matches the specified filter. If multiple documents satisfy the condition, only one matching document is removed. This makes the operation appropriate when the application expects a single target document or when deletion must be deliberately limited. Administrators should construct the filter carefully because an overly broad condition can delete an unintended document. When multiple matching documents need to be removed, a different operation such as deleteMany() is more appropriate. Before destructive operations, DBAs should validate the filter against representative data and follow appropriate backup and change-control procedures.

Question 143

Which MongoDB method removes every matching document from a collection?

  1. deleteAll()
  2. removeMany()
  3. deleteMany()
  4. eraseMatching()

Correct Answer: 3

Explanation:

deleteMany() removes all documents that match the supplied filter. Unlike deleteOne(), it does not stop after removing the first matching document. This makes it useful for bulk cleanup operations, retention tasks, or removing a defined class of records. Because the operation can affect a large number of documents, administrators should test the filter carefully before executing it in production. Appropriate indexing can also influence the efficiency of locating matching documents. For important data, DBAs should verify backup and recovery procedures before performing large-scale deletion operations.

Question 144

Which MongoDB operator removes a field during an update?

  1. $delete
  2. $unset
  3. $remove
  4. $clear

Correct Answer: 2

Explanation:

The $unset update operator removes a specified field from matching documents. It is useful when an application needs to eliminate obsolete attributes while retaining the remainder of each document. The operator can be applied through update methods using an update document containing the relevant field names. Removing a field differs from assigning it a null value because $unset eliminates the field from the document structure. DBAs should consider application expectations, indexes, validation rules, and schema conventions before performing large-scale field removal operations.

Question 145

Which MongoDB operator increments a numeric field by a specified amount?

  1. $add
  2. $sum
  3. $inc
  4. $increase

Correct Answer: 3

Explanation:

The $inc update operator increments a numeric field by the specified amount. It can increase or decrease a value when a positive or negative increment is supplied. This makes it useful for counters, quantities, sequence-related values, and other numeric attributes. The operation is performed atomically at the document level, which helps avoid application-side read-modify-write patterns for simple counters. Administrators should ensure that the target field contains compatible numeric data. Using $inc directly can simplify concurrent updates because MongoDB performs the modification within the database operation.

Question 146

Which command inserts several documents in one database operation?

  1. insertBatch()
  2. insertMany()
  3. bulkCreate()
  4. addDocuments()

Correct Answer: 2

Explanation:

insertMany() inserts multiple documents into a collection through a single database method call. It is useful when applications or administrative scripts need to add batches of documents efficiently. MongoDB supports ordered and unordered insertion behavior, allowing applications to choose how errors affect processing of the remaining documents. Batch size should be selected appropriately because extremely large batches can increase memory and processing requirements. DBAs should also consider indexes because each inserted document may require index maintenance. Proper batching can improve throughput while keeping resource consumption manageable.

Question 147

Which MongoDB command updates multiple documents matching a filter?

  1. updateMany()
  2. updateAllRecords()
  3. modifyBatch()
  4. changeMany()

Correct Answer: 1

Explanation:

updateMany() applies an update operation to every document matching the supplied filter. It is useful for bulk modifications such as changing status values, adding fields, or adjusting data according to an administrative rule. Because many documents can be affected, the filter should be validated carefully before execution. Administrators should also consider index support, replication traffic, journaling, and application impact during large updates. For very large datasets, DBAs may prefer controlled batching or maintenance windows depending on the workload. Monitoring resource consumption helps prevent bulk updates from overwhelming production systems.

Question 148

Which operator adds a value to an array field without creating duplicates?

  1. $push
  2. $appendUnique
  3. $addToSet
  4. $arrayAdd

Correct Answer: 3

Explanation:

The $addToSet update operator adds a value to an array only when that value is not already present. This makes it useful when an application needs to maintain a collection of unique array elements. It differs from $push, which adds an element without enforcing uniqueness. $addToSet can therefore help prevent duplicate values in suitable array fields without requiring the application to perform a separate existence check. DBAs should still consider array growth because very large arrays can affect document size and update performance. Appropriate schema design remains important for frequently modified array data.

Question 149

Which MongoDB operator appends an element to an array?

  1. $insertArray
  2. $append
  3. $push
  4. $arrayInsert

Correct Answer: 3

Explanation:

The $push operator appends a value to an array field. It is commonly used when applications need to add items such as events, tags, references, or other ordered values to an existing array. Unlike $addToSet, $push does not inherently prevent duplicate elements. Additional modifiers can control aspects such as sorting or limiting an array after insertion. Administrators should monitor document growth when arrays are frequently expanded because MongoDB documents have a maximum BSON document size. For workloads involving continuously growing arrays, an alternative schema may be more appropriate.

Question 150

Which MongoDB operator removes an array element matching a condition?

  1. $pull
  2. $extract
  3. $removeArray
  4. $discard

Correct Answer: 1

Explanation:

The $pull update operator removes array elements that match a specified condition. It is useful for cleaning individual values from arrays without replacing the entire document. For example, applications can remove obsolete tags or matching embedded array entries through a single update operation. Because the condition determines which elements are removed, administrators should test complex predicates carefully before running bulk updates. $pull operates on stored document arrays and can affect multiple elements within each matching document. Indexing and document size should also be considered when performing large-scale array cleanup.

Question 151

Which MongoDB command creates a collection explicitly?

  1. db.makeCollection()
  2. db.createCollection()
  3. db.newCollection()
  4. db.addCollection()

Correct Answer: 2

Explanation:

db.createCollection() explicitly creates a collection and allows administrators to specify supported collection options during creation. This can be useful when configuring capped collections, validation rules, time-series behavior, or other collection characteristics that need deliberate setup. MongoDB can also create collections implicitly when data is inserted, but explicit creation gives administrators greater control over initial configuration. DBAs should determine required options before creating a production collection because some collection properties are not interchangeable after creation. Proper naming and validation planning can also prevent later migration work.

Question 152

Which MongoDB command removes a collection and its documents?

  1. db.collection.erase()
  2. db.collection.deleteCollection()
  3. db.collection.drop()
  4. db.collection.removeAll()

Correct Answer: 3

Explanation:

The drop() method removes a collection and its associated data from the database. It is a destructive operation and should be used carefully, particularly in production environments. Dropping a collection also removes its indexes because they belong to that collection. Administrators should verify the collection name and database context before execution. Unlike deleting individual documents, dropping a collection removes the entire collection object. DBAs should consider application dependencies, backup availability, and recovery requirements before performing this operation.

Question 153

Which MongoDB command creates an index on a collection?

  1. db.collection.createIndex()
  2. db.collection.addIndex()
  3. db.collection.buildIndex()
  4. db.collection.indexCreate()

Correct Answer: 1

Explanation:

db.collection.createIndex() creates an index using the specified key pattern and supported options. Indexes can significantly improve query performance by allowing MongoDB to locate matching documents more efficiently. However, every index also consumes storage and adds maintenance work during writes. DBAs should therefore create indexes based on actual query patterns rather than indexing every field indiscriminately. Before adding an index, administrators should review existing indexes and analyze representative query plans. Index creation on large production collections should also be planned with awareness of resource usage and operational impact.

Question 154

Which MongoDB method removes a specific index from a collection?

  1. dropIndex()
  2. removeIndex()
  3. deleteIndex()
  4. eraseIndex()

Correct Answer: 1

Explanation:

dropIndex() removes a specified index from a collection. Administrators may use it when an index is obsolete, redundant, or no longer justified by the workload. Before dropping an index, DBAs should review query patterns and usage information because an index that appears unnecessary may support infrequent but important operations. Removing an index can reduce storage requirements and write-maintenance overhead, but it may also cause queries to choose less efficient execution plans. Index changes should therefore be tested and monitored, particularly in high-traffic production environments.

Question 155

Which query operator matches documents where a field exists?

  1. $exists
  2. $present
  3. $defined
  4. $available

Correct Answer: 1

Explanation:

The $exists query operator tests whether a specified field is present in a document. It can be used to distinguish documents that contain a field from those that do not. This is useful in collections with optional attributes or evolving schemas. $exists does not determine whether the field contains a particular non-null value; it focuses on field presence. Administrators should understand this distinction when writing cleanup queries, validation checks, or migration scripts. Appropriate indexes may improve queries that combine field-existence tests with other selective predicates.

Question 156

Which MongoDB operator matches values against a regular expression?

  1. $pattern
  2. $regex
  3. $regexpMatch
  4. $textPattern

Correct Answer: 2

Explanation:

The $regex query operator matches string fields against a regular expression pattern. It can support flexible text-pattern searches when exact equality is insufficient. However, regular-expression queries can become expensive, especially when patterns prevent effective index use or scan large portions of a collection. DBAs should examine explain plans and workload behavior when regular expressions are used frequently. Anchored patterns may behave differently from unanchored patterns in terms of index support. For advanced search requirements, specialized search capabilities may provide more predictable functionality and performance than broad regular-expression queries.

Question 157

Which MongoDB query operator matches any value from a supplied list?

  1. $in
  2. $anyOf
  3. $oneOf
  4. $members

Correct Answer: 1

Explanation:

The $in query operator matches documents where a field equals any value from the supplied array of values. It is useful when an application needs to retrieve records belonging to several known categories without issuing separate queries. Query performance depends on the number of supplied values, available indexes, and overall data distribution. Very large $in arrays can increase planning and execution work. DBAs should evaluate representative workloads and use appropriate indexes when $in conditions are common. The operator is different from $nin, which selects values outside the supplied set.

Question 158

Which MongoDB operator matches documents where all array elements satisfy specified conditions?

  1. $every
  2. $all
  3. $each
  4. $arrayMatch

Correct Answer: 2

Explanation:

The $all query operator matches arrays that contain all specified values. It is useful when an application needs documents whose array field includes several required elements. $all differs from $in, which matches when at least one supplied value is present. Understanding the distinction is important when constructing filters for tags, categories, permissions, or other multi-valued fields. Administrators should also consider array indexing and data distribution when optimizing these queries. Complex array predicates should be tested with realistic documents to ensure that the matching semantics align with application requirements.

Question 159

Which MongoDB operator combines multiple query conditions with logical AND behavior?

  1. $allConditions
  2. $and
  3. $everyCondition
  4. $conjunction

Correct Answer: 2

Explanation:

The $and logical operator requires all specified query expressions to evaluate as true for a document to match. MongoDB can often express simple conjunctions directly by placing multiple field conditions in the same query document, but $and is useful when explicit logical grouping is needed. It can also combine conditions involving the same field in ways that cannot always be represented by a simple object structure. DBAs should examine query plans when complex logical predicates are used. Appropriate indexes can improve selective conditions, although not every branch of a compound logical expression will necessarily use the same index.

Question 160

Which MongoDB operator selects documents that do not match a condition?

  1. $exclude
  2. $notMatch
  3. $not
  4. $negative

Correct Answer: 3

Explanation:

The $not query operator performs a logical negation of another operator expression. It can be used when documents should be selected because a specified condition does not match. $not is commonly combined with comparison or regular-expression operators rather than serving as a standalone replacement for every negative query requirement. Negative predicates can sometimes be less selective than positive predicates, which may affect index efficiency. DBAs should inspect execution plans and test query performance against realistic data volumes when applications depend heavily on exclusion-oriented filtering.