An application needs to update a document in the 'orders' collection. If the document matching the query does not exist, a new document must be inserted using fields from both the query and the update document. Which parameter accomplishes this behavior?
A developer is writing a bulk operation against the 'inventory' collection using db.inventory.bulkWrite(). The batch must (1) insert a new item only if no document already exists with the same 'sku', and (2) increment the 'qty' field of an existing item by 5 in the same round trip. Which two operations should be included in the bulkWrite array to meet these requirements? (Choose two.)
A booking system stores reservations in the 'reservations' collection. Each document has a 'guests' array of embedded subdocuments, each with 'name' and 'checkedIn' fields. An operator needs to mark only the subdocument whose 'name' is 'M. Chen' as checked in, leaving all other array elements unchanged. Which update accomplishes this?
A monitoring service writes metric documents with a 'sensorId' field to the 'metrics' collection. The application occasionally retries writes and must avoid creating duplicate documents when a document with the same 'sensorId' already exists. The update should set 'lastSeen' to the current date and increment a 'readings' counter when the sensor already exists. Which operation meets both requirements?
A developer needs to retrieve documents from the 'sensors' collection where the 'readings' array contains at least one element greater than 100, but the query must return only the first matching element from each array. Which projection correctly limits the returned array to the first matching element?
A logistics application stores shipment documents in the 'shipments' collection, where each document has an 'events' array of subdocuments containing 'status' and 'timestamp' fields. A developer must append a new event to the 'events' array only if no event with the same 'status' and 'timestamp' already exists, to avoid duplicate entries during retries. Which update operation achieves this?
A developer is working with a 'logs' collection where each document has a field 'timestamp' of type Date. They need to find all documents where the timestamp is in the year 2023. Which two queries will achieve this? (Choose two.)
A media application stores user profiles in the 'profiles' collection. A developer must remove a deprecated field named 'legacyScore' from all documents in the collection without affecting any other fields or documents. Which two operations accomplish this? (Choose two.)
A social media application stores user profiles in the 'profiles' collection. Each document has a field 'username' that should be unique. You need to insert a new profile document, but only if the username does not already exist. If it exists, the insert should fail and return an error. Which method should you use?
An application needs to update a user document in the 'users' collection. If the document does not exist, a new document must be inserted using fields from both the filter and the update document. Which parameter accomplishes this behavior in MongoDB?
You are designing an e-commerce catalog where products can have a dynamic array of tags. You need to query for documents where the 'tags' array contains both 'electronics' and 'sale' simultaneously, regardless of their order or other elements. Which query operator should you use?
A support ticketing system stores documents in the 'tickets' collection. An operator wants to add a new field 'priority' set to 'high' only for tickets whose 'status' is 'open' and that do not already have a 'priority' field. The update must not create any new documents and must not modify tickets that already have a 'priority' field. Which update operation should be used?
A logistics application stores shipment documents in the 'shipments' collection. Each document has a 'packages' array of embedded subdocuments, each with a 'trackingCode' field. A developer needs to remove only the embedded subdocument whose 'trackingCode' equals 'TRK-9981' from the document with '_id' 42, leaving all other packages untouched. Which update operation should be used?
A reporting service reads from the 'sensors' collection, which holds millions of documents each containing an 'active' boolean field. The service queries only for documents where 'active' is true and reads a handful of fields. A developer wants the query to avoid scanning documents that are inactive. Which index should be created to support this access pattern most directly?
A logistics application stores shipment records in the 'shipments' collection. Each document includes a 'status' field and a 'deliveredAt' field (a Date). A developer must set 'deliveredAt' to the current date and time for every shipment whose 'status' is 'in_transit' and whose 'carrier' is 'FastShip'. Which operation satisfies this requirement with a single command?
An analytics job updates counters in the 'metrics' collection with db.metrics.updateOne({ metric: "visits" }, { $inc: { count: 1 } }). The job runs with write concern w:1 against a three-node replica set, and a failover occurs immediately after the primary acknowledges a write. The developer reports that a counter increment appears to be lost. Which statement best explains this outcome?
A developer is exploring a 'reviews' collection and wants to retrieve only the 'author' and 'rating' fields from every review document, without the _id field, to reduce the payload sent to the application. Which query accomplishes this?
A logistics MongoDB deployment has a 'shipments' collection. A nightly job must remove the 'tracking_history' array element whose 'status' is 'cancelled' from every document where 'carrier' is 'DHL', without deleting the documents themselves. Which update operation should the developer run?
A developer is writing a Python application using the official MongoDB driver to insert a single document into the 'inventory' collection. They call `inventory.insert_one({'sku': 'A100', 'qty': 5})`. Which statement accurately describes what happens?
A reporting service reads from the 'sensor_readings' collection, which contains millions of documents. The service runs a query that filters on 'deviceId' and returns results sorted by 'recordedAt' descending. The query performs a collection scan and an in-memory sort, causing high memory usage. Which index should you create to allow the query to use an index for both filtering and sorting?
A MongoDB application stores inventory documents in the 'inventory' collection with fields 'sku', 'on_hand', and 'reserved'. During a flash sale, many concurrent sessions must decrement 'on_hand' by 1 only when on_hand is greater than 0, and each successful decrement must return the resulting document to the client. Which approach guarantees this behavior?
A logistics application stores shipment records in the 'shipments' collection. A developer must delete all shipment documents whose 'status' field equals 'cancelled'. Which command correctly performs this operation?
A developer needs to insert a single document into the 'inventory' collection and wants the operation to return the generated _id value in the result. Which method should be used?
A sensor platform writes readings to the 'readings' collection. A developer needs to insert three documents in a single operation and have the server process them in the given order, stopping at the first error rather than continuing. Which insert command should be used?
A developer wants to remove all documents from the 'logs' collection where the 'level' field equals 'debug'. The collection has an index on level. Which operation should be used, and what does it return?
An inventory collection stores documents with a numeric 'quantity' field. A warehouse system must decrement quantity by 5 on a specific item, and if the field is missing it should be created starting from the decremented value. Which update operator and command achieve this?
A developer queries the 'events' collection with db.events.find({ tags: { $in: ["sports", "music"] } }) and observes a COLLSCAN in explain output even though an index exists on the 'tags' array field. The collection holds a few hundred documents. Which explanation best accounts for the planner choosing a collection scan?
A developer must update a document in the 'accounts' collection by incrementing the 'balance' field by 25 and simultaneously setting the 'lastUpdated' field to the current date. The update must apply only if the account is active. Which update statement satisfies all conditions?
A document in the 'profiles' collection has an embedded array 'contacts' of subdocuments, each with 'type' and 'value' fields. A developer must change the 'value' of the subdocument whose 'type' is 'email' without altering any other array element. Which update is correct?
A developer is troubleshooting a Python application that uses the MongoDB driver to query the 'products' collection with find({'category': 'tools'}). Which two statements about the returned cursor are correct? (Choose two.)
A developer is querying the 'events' collection to retrieve documents and needs to control which fields are returned to reduce network payload. Which two statements about projection in MongoDB find() operations are correct? (Choose two.)
A logistics application stores shipment events in the 'shipments' collection. Each document contains a field 'events' that is an array of subdocuments with fields 'status' and 'timestamp'. You need to remove the subdocument where 'status' equals 'cancelled' from all documents in the collection, without affecting other array elements. Which update operation should you use?
A banking application must atomically transfer funds between two account documents in the 'accounts' collection. The transfer decreases the balance of the source account and increases the balance of the destination account, and both changes must succeed or neither should be applied. The deployment is a replica set. Which approach guarantees this atomicity?
A financial application stores transactions in the 'transactions' collection. Each document has fields: 'accountId', 'amount', 'timestamp', and 'status'. You need to find all transactions for account 'A123' that have an amount greater than 1000 and a status of either 'pending' or 'review'. Which two query documents correctly retrieve these transactions? (Choose two.)
A blog platform stores posts in the 'posts' collection. Each document has an array field 'comments' containing subdocuments with fields 'author' and 'text'. You need to add a new comment to the 'comments' array of a specific post identified by its '_id'. The new comment should be appended to the end of the array. Which update operation should you use?