MongoDB / Intermediate: aggregation and application contracts / Lesson 14
Bulk writes and partial outcomes
Account for ordered and unordered write errors and reconcile a synthetic batch.
On this page
Lesson goals
- Explain ordered and unordered bulk behavior.
- Identify partial success after a duplicate-key error.
- Design safe reconciliation and bounded retry.
- Classify successful, failed, unattempted and uncertain batch operations.
- Design bounded reconciliation and retries that preserve operation identity.
Define the batch boundary
A bulk write groups multiple operations for efficient submission, but it is not automatically a single all-or-nothing business transaction. Choose ordered execution when later operations depend on earlier ones, and understand the documented error behavior of the deployed driver and transaction context. Record stable source identities and the intended result for each operation before sending a batch.
Cause an ordered write error
The illustrative mongosh example uses a new disposable MongoDB 8.0-compatible collection outside a transaction. It inserts an existing identifier, then submits three ordered inserts. The second insert conflicts with that identifier. Run only in an isolated lab; the public example does not access a configured database or assert actual server output.
db.lab_import.insertOne({ _id: 1, label: "existing" });
db.lab_import.bulkWrite([
{ insertOne: { document: { _id: 2, label: "new" } } },
{ insertOne: { document: { _id: 1, label: "duplicate" } } },
{ insertOne: { document: { _id: 3, label: "later" } } }
], { ordered: true });
The first batch item can insert id 2, the second encounters the existing id 1, and ordered processing stops before id 3. Inspect the driver’s error and write-concern details; outcomes depend on successful connection and the stated fixture.
Inspect the resulting documents
After the error, query the disposable collection and compare it with the source batch and the returned write information. A failure response does not imply that the earlier successful item was undone. The following read is illustrative; in a real application use authorized, appropriately scoped queries and avoid exposing private documents in logs.
db.lab_import.find({}, { _id: 1, label: 1 }).sort({ _id: 1 });
Under the declared ordered scenario, ids 1 and 2 exist and id 3 was not attempted. This is reasoning from the fixture, not a claimed live result. Inspect the actual error and collection before deciding what to retry.
Understand unordered execution
Outside a transaction, unordered bulk processing can continue with remaining operations after an individual write error and can execute them in a different order. Therefore operations must not depend on a specific ordering. Write concern errors and transaction behavior need separate interpretation using the driver documentation. A batch result can contain both successful and failed work, so retain enough identity to reconcile each intended operation.
Test retry and uncertainty
In an isolated environment, test ordered and unordered batches, a duplicate key, and a lost response after submission. Verify the actual documents and the driver’s structured results before retrying. Use stable operation identifiers and an idempotent strategy suitable for the business action; do not simply resubmit non-idempotent increments. Compare final counts and representative fields with the source manifest, including operations that were not attempted.
Define the batch and its identity
A bulk write submits a list of operations, but a collection bulk outside a transaction is not automatically one atomic business event. Before submission, create a source manifest that maps each operation index to a stable business identifier, intended change and expected preconditions. Distinguish insert, update, replacement and delete: an update that matches zero documents can be a successful database operation while failing the business objective. Record whether an upsert is allowed and what constitutes a duplicate versus an already completed request. Without that contract, an aggregate count cannot explain which source item needs repair.
The examples use the Node.js driver collection bulk API and MongoDB 8.0 semantics unless a trace explicitly says otherwise. The server also introduced a database command for multiple namespaces in 8.0, but collection bulk and client-level bulk have different APIs and result/error shapes; do not transfer fields blindly between them. Verify the installed driver and server compatibility. Every fixture here is synthetic, and no collection, write, driver response or benchmark was observed during authoring.
Choose order according to dependencies
Outside a transaction, ordered operations run in the supplied order and stop after an individual write error; earlier successful operations are not rolled back merely because a later item failed. If the second of four independent inserts fails on a duplicate key, the first may have succeeded and the last two are not attempted in that ordered sequence. Reconcile the actual partial result and stored state before deciding the next action. Ordered submission preserves sequence, but it does not make the entire batch all-or-nothing and does not replace a transaction when a cross-document invariant requires atomic commit.
Unordered mode may reorder operations and attempts remaining operations after individual write errors outside a transaction. It is suitable only when correctness does not depend on list order. An insert followed by an update to that same new document is not independent: running the update first can produce a different result. Separate dependent phases or use a design with explicit sequencing. Do not infer the exact parallel schedule or claim a speedup from the unordered flag; workload, deployment and driver behavior determine actual performance.
Read partial results without overclaiming
A collection bulk error in the Node.js driver can include writeErrors, writeConcernErrors and a result describing successful work. A write error identifies an individual operation failure such as a duplicate key or validation rejection. A write concern error concerns the requested acknowledgment and must be analyzed separately; it does not automatically prove that no write took effect. A network failure or lost response can leave the application uncertain about which operations reached the server. Preserve structured information supported by the installed driver and map error indexes back to the original manifest rather than relying on full human-readable messages.
Counts are useful but have limits. matchedCount describes matched updates, whereas modifiedCount describes documents actually modified; an update setting an already equal value may match without modifying. An upsert inserts when its filter has no match and the option permits it, so track upserted results separately. An aggregate count is not a substitute for per-item identity and appropriate reads: multiple operations can affect the same document, and a no-match update may still be unacceptable to the business. Check the actual result shape for the chosen API and version.
Reconcile before retrying
Partition the manifest into confirmed successes, confirmed write failures, known unattempted operations, and uncertain outcomes. The exact evidence for each category depends on the API, error and acknowledgment; do not call an operation unattempted merely because its result is missing after a network failure. Compare stable identifiers and expected postconditions with appropriately scoped reads where the application’s consistency contract permits. Preserve original indexes when forming a repair batch so a later error can still be traced to the source record. Track rejected records rather than silently dropping them.
Blindly retrying the whole batch is dangerous when it contains $inc, inserts without a stable identity, or other non-idempotent business effects. A stable operation identifier, unique constraint or durable request record can support an idempotent design, but its exact implementation must match the business invariant. A duplicate-key response on retry may mean the earlier request succeeded or a different record conflicts; inspect identity and content before deciding. Limit attempts, define an escalation path for unresolved uncertainty, and test response loss separately from a known duplicate error.
Test transaction and operational boundaries
A bulk call inside a transaction has transaction-specific error and abort behavior; do not apply an outside-transaction partial-success rule without checking the documented API and transaction outcome. A transaction can give the participating writes an atomic commit boundary, but every intended operation must use the right session and business checks. Write concern belongs at the transaction boundary. A successful bulk call alone does not prove a later commit succeeded, and an unknown commit result must be handled according to the driver’s transaction guidance.
Test a small disposable fixture with a mid-list duplicate, a no-match update, a validation failure and a lost response. Compare ordered and unordered cases only where operations are independent; verify the final documents and the structured result, not just the thrown exception. Record batch size, workload and deployment if measuring performance, but do not turn a toy trace into a benchmark. The code and outputs in this chapter are unexecuted reasoning; no production, learner or other real database is contacted.
20 worked examples
1. Ordered mid-list error
Problem: Which items are attempted after a known duplicate?
- The first two inserts precede the duplicate ID 4.
- The individual write error at 4 stops the ordered sequence before 5.
outside transaction; ordered:true
existing IDs: [4]
operations: insert 2, insert 3, insert 4, insert 5
assumption: no other errors
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: IDs 2 and 3 succeed; 4 fails; 5 is unattempted.
Why this result follows: The individual write error at 4 stops the ordered sequence before 5.
2. Unordered independent inserts
Problem: What can be concluded about remaining independent items?
- The duplicate affects the operation inserting the existing ID 4.
- Unordered processing attempts the other independent items despite that write error, without a list-order guarantee.
outside transaction; ordered:false
existing IDs: [4]
operations: insert 2, insert 4, insert 5
assumption: only duplicate 4 fails; no other interruption
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: IDs 2 and 5 succeed under the stated assumptions; 4 fails.
Why this result follows: Unordered processing attempts the other independent items despite that write error, without a list-order guarantee.
3. First ordered item fails
Problem: Which later operations are known unattempted?
- The first listed insert encounters the declared duplicate.
- Ordered processing stops at that error before either later operation.
outside transaction; ordered:true
existing IDs: [7]
operations: insert 7, insert 8, delete 9
assumption: duplicate 7 is the first write error
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: Insert 8 and delete 9 are unattempted.
Why this result follows: Ordered processing stops at that error before either later operation.
4. No-match update
Problem: Does a successful update call prove its target existed?
- The filter matches no document in the declared fixture.
- The operation can complete with zero matches, so the application must check whether that meets its business rule.
operation: updateOne filter {_id:9}, set status='sent'
fixture: no document with _id 9
upsert: false
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: Expected match count is zero; no document is updated.
Why this result follows: The operation can complete with zero matches, so the application must check whether that meets its business rule.
5. Matched but unchanged
Problem: Why can matched and modified counts differ?
- The identifier matches the existing document.
- The set value equals the stored value, so the document need not be modified.
before: {_id:1,status:'sent'}
operation: updateOne {_id:1}, {$set:{status:'sent'}}
assumption: acknowledged operation
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: Expected matched count 1, modified count 0.
Why this result follows: The set value equals the stored value, so the document need not be modified.
6. Upsert inserts on no match
Problem: What happens under this explicit upsert assumption?
- The filter has no match in the stated fixture.
- The explicit upsert option permits an insertion built from the filter and update.
fixture: no document with _id 3
operation: updateOne {_id:3}, {$set:{status:'new'}}, upsert:true
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: One document with _id 3 and status new is upserted.
Why this result follows: The explicit upsert option permits an insertion built from the filter and update.
7. Unordered dependency hazard
Problem: Why is insert then update unsafe as an unordered dependency?
- The unordered update can be attempted before the insert.
- If it runs first it matches nothing, while the opposite order would increment the new document.
initial: no _id 1
operations: insert {_id:1,n:0}; update {_id:1} {$inc:{n:1}}
ordered:false; upsert:false
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: The final n is order-dependent; separate or order the phases.
Why this result follows: If it runs first it matches nothing, while the opposite order would increment the new document.
8. Write error versus concern error
Problem: What does a write concern error establish?
- A write concern error concerns the requested acknowledgment.
- It does not by itself establish that every write failed or that no change occurred.
batch submitted; writeConcernError reported (assumed)
actual post-write state: not yet reconciled
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: Reconcile the actual outcome before retrying.
Why this result follows: It does not by itself establish that every write failed or that no change occurred.
9. Lost response
Problem: Can every operation be classified as unattempted?
- The client has no definitive result for the submitted batch.
- Missing results after network loss do not prove that the server attempted none of the items.
manifest: operations A, B, C
request sent; response lost
server state: unknown
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: Classify outcomes as uncertain pending reconciliation.
Why this result follows: Missing results after network loss do not prove that the server attempted none of the items.
10. Retrying an increment
Problem: What risk follows a blind retry after a lost response?
- The first increment may already have changed five to six.
- If it did, a second application can raise the count to seven instead of the intended six.
before: {_id:1,count:5}
operation: {$inc:{count:1}}
response: lost; client retries blindly
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: A duplicate increment is possible.
Why this result follows: If it did, a second application can raise the count to seven instead of the intended six.
11. Stable operation identity
Problem: How can a retry be reconciled with the first attempt?
- Both attempts carry the same business operation identifier R12.
- The durable record and expected state can be checked before deciding whether a new effect is needed.
source operation: R12
response: lost
retry request: R12
policy: durable unique operation record and postcondition
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: Reconcile R12 before applying the effect again.
Why this result follows: The durable record and expected state can be checked before deciding whether a new effect is needed.
12. Duplicate retry is ambiguous
Problem: Does a duplicate key prove this exact request already succeeded?
- The identifier already exists, but the stored amount differs from the intended request.
- The conflict could represent different content, so identity and payload must be reconciled rather than declared successful.
retry insert: {_id:'R1',amount:5}
existing: {_id:'R1',amount:9}
result: duplicate key (assumed)
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: Treat the mismatch as a conflict for review.
Why this result follows: The conflict could represent different content, so identity and payload must be reconciled rather than declared successful.
13. Map error index to source
Problem: Which source item corresponds to the reported error index?
- The manifest preserves the original zero-based operation positions.
- Index 1 maps to source item B, even if its business identifier differs from the index.
manifest indexes: 0->A, 1->B, 2->C
write error index: 1 (assumed)
API: collection bulk
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: Investigate source item B.
Why this result follows: Index 1 maps to source item B, even if its business identifier differs from the index.
14. Validation error in ordered list
Problem: What happens after the invalid second item?
- The validator rejects B under the stated error action.
- The ordered sequence stops at that individual write error, so C is not attempted.
outside transaction; ordered:true; validationAction:error
operations: valid A, invalid B, valid C
assumption: A succeeds; B fails validation
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: A succeeds; B fails; C is unattempted.
Why this result follows: The ordered sequence stops at that individual write error, so C is not attempted.
15. Unordered multiple failures
Problem: Why retain all reported individual errors?
- The unordered batch attempts independent items despite individual write errors.
- Both B and C need distinct remediation while A and D may succeed under the stated assumptions.
outside transaction; ordered:false
operations: A valid, B duplicate, C invalid, D valid
assumption: no other interruption
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: Reconcile B and C separately from A and D.
Why this result follows: Both B and C need distinct remediation while A and D may succeed under the stated assumptions.
16. Delete no match
Problem: What does a zero delete count mean for a required deletion?
- No stored document satisfies the declared filter.
- A zero deletion can be a valid database outcome but fails the stated business requirement.
fixture: no document with _id 8
operation: deleteOne {_id:8}
business requirement: exactly one deletion
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: Investigate the unmet deletion precondition.
Why this result follows: A zero deletion can be a valid database outcome but fails the stated business requirement.
17. Bulk inside an aborted transaction
Problem: What survives an explicitly aborted transaction?
- Both writes are participating operations of the aborted transaction.
- Their transactional database changes do not commit merely because an intermediate bulk operation returned.
transaction session: S
bulk operations A and B: both use S
transaction outcome: abort
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: Neither participating change commits on abort.
Why this result follows: Their transactional database changes do not commit merely because an intermediate bulk operation returned.
18. Collection versus client bulk
Problem: Can a collection error shape be copied to a client bulk handler?
- Collection and client bulk APIs have different scope and documented result and error types.
- An adapter must inspect the installed driver’s API rather than assuming identical fields.
server baseline: 8.0
API A: collection.bulkWrite
API B: client-level bulkWrite (driver/version permitting)
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: Use the result contract for the selected API.
Why this result follows: An adapter must inspect the installed driver’s API rather than assuming identical fields.
19. Reconcile manifest categories
Problem: Do the categories cover the batch?
- The stated categories are mutually exclusive for this accounting.
- Their sum is ten, matching the manifest while leaving two outcomes unresolved.
manifest count: 10
confirmed success: 5
confirmed failures: 2
known unattempted: 1
uncertain: 2
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: All 10 are accounted for; 2 remain uncertain.
Why this result follows: Their sum is ten, matching the manifest while leaving two outcomes unresolved.
20. Two updates to one document
Problem: Why can operation count differ from distinct document count?
- Both update operations target the same identifier.
- Two successful operations can therefore change one distinct document, not two separate documents.
initial: {_id:1,a:0,b:0}
ordered operations: set a=1; set b=1
assumption: both succeed
The outcome is reasoned under the assumptions; no write was sent to a database.
Expected result: Two operations affect one distinct document.
Why this result follows: Two successful operations can therefore change one distinct document, not two separate documents.
Common errors and fixes
The caller assumes no writes occurred after an error.
- Why it happens
- Earlier ordered operations may have succeeded before the failing item.
- How to fix it
- Inspect the structured result and reconcile actual documents.
- Prevent it next time
- Test a mid-batch failure in a disposable collection.
An unordered batch produces an unexpected final state.
- Why it happens
- Operations depended on execution order.
- How to fix it
- Separate dependent operations or choose a suitable ordered workflow.
- Prevent it next time
- Design unordered items to be independent.
A retry duplicates an increment.
- Why it happens
- The client repeated a non-idempotent operation after an uncertain response.
- How to fix it
- Reconcile by stable operation identity before retrying.
- Prevent it next time
- Test lost responses and idempotency.
20 practice exercises
1. Which ids exist after the illustrated ordered failure under the stated assumptions?
Show hint
Separate the preexisting ID from the successful item and the item after the error.
Show worked solution
Ids 1 and 2 exist. Id 1 was inserted before the batch; id 2 is the first successful item. The duplicate id 1 stops processing before id 3.
The preexisting ID 1 remains and ID 2 succeeds before the duplicate 1. Ordered processing stops before attempting 3 under the fixture; the error does not roll back the earlier insert.
Check your solution
- IDs 1 and 2 exist.
- The operation for ID 3 was not attempted.
2. Can an unordered batch be assumed to execute in list order?
Show hint
Consider independence rather than the item’s position in the list.
Show worked solution
No. Outside a transaction, unordered processing can reorder operations and continue after an individual write error. Use independent operations and inspect the driver result.
Outside a transaction unordered items may be reordered and remaining operations attempted after an individual write error. Design items independently and inspect the structured result rather than assuming list order.
Check your solution
- List order is not assumed.
- Partial results are reviewed after an individual write error.
3. Outside a transaction, ordered inserts 2, 3, 4 and 5 encounter existing ID 4. Classify each item and construct a repair plan that preserves source identity.
Show hint
Stop at the duplicate and distinguish failed from unattempted work.
Show worked solution
Under the stated assumptions 2 and 3 succeed, 4 fails and 5 is unattempted. Investigate the conflicting 4 rather than replaying successes, then carry the original identity for 5 into a reviewed repair batch.
Check your solution
- IDs 2 and 3 are not blindly replayed.
- Failed 4 and unattempted 5 are handled separately.
4. Compare ordered and unordered behavior for independent inserts A, duplicate B and C outside a transaction; assume no interruption.
Show hint
Separate continuation from execution order.
Show worked solution
Ordered processing succeeds at A, fails at B and does not attempt C. Unordered processing attempts all independent items, allowing A and C to succeed under the assumptions, but does not guarantee their execution order.
Check your solution
- C is unattempted in the ordered case.
- C is attempted in the unordered case.
5. A list inserts document X and then increments X. Explain why unordered mode is unsafe and propose a sequencing repair.
Show hint
Consider the update running before the insert.
Show worked solution
If the update runs first with upsert disabled it can match nothing; if the insert runs first it can increment X. Use ordered execution or separate dependent phases and check the update result.
Check your solution
- The two possible orders have different outcomes.
- The repair explicitly sequences the dependent operations.
6. An updateOne for ID 9 returns matchedCount 0 with upsert false, but the manifest requires one update. Compare a missing target with a stale filter and plan the next check.
Show hint
Both causes can produce zero matches; inspect identity and expected state.
Show worked solution
The technical result is zero matches and the business requirement is unmet. Read the authorized target by stable identity and compare the expected version or status before deciding whether it is missing or the filter is stale; do not blindly widen the filter.
Check your solution
- The zero match is not reported as business success.
- Identity and expected state are checked before repair.
7. A document already has status:"sent" and an update sets it to that value. Explain expected matched and modified counts and the limitation of each.
Show hint
Matching a document does not guarantee a changed value.
Show worked solution
The update can match one document while modifying zero because the value is unchanged. Matched count establishes the filter match, whereas modified count records actual modification; neither alone proves an external business effect.
Check your solution
- The expected counts are matched 1 and modified 0.
- The counts do not establish an external effect.
8. An update has no matching ID 5. Compare upsert:false and upsert:true for a $set of status:"new".
Show hint
The option changes the no-match behavior.
Show worked solution
With upsert false the update matches nothing and creates no document. With upsert true the operation can insert a document from the equality filter and update, so record the upsert separately from matched updates.
Check your solution
- The false case creates no document.
- The true case can create ID 5 with status new.
9. A write concern error arrives after a submitted batch. Explain why neither full success nor no write can be assumed.
Show hint
Acknowledgment and individual write effects are different evidence.
Show worked solution
The requested acknowledgment was not established as expected, but the error alone does not identify every write’s durable outcome. Inspect the supported structured details and reconcile stable identifiers and postconditions before retrying.
Check your solution
- The batch is not declared wholly absent.
- Reconciliation precedes retry.
10. A response is lost after operations A, B and C were sent. Design a manifest classification without assuming which operations ran.
Show hint
Missing response is uncertainty, not evidence of non-attempt.
Show worked solution
Mark A, B and C uncertain until supported results or appropriately scoped reconciliation resolve them. Preserve their original identifiers and do not label them unattempted solely because the response is missing.
Check your solution
- All unresolved items remain uncertain.
- The original identifiers are retained.
11. A manifest has A confirmed successful, B a reported duplicate, and C with no result after a connection loss. Classify each and state what evidence C needs.
Show hint
Do not call the missing result unattempted without evidence.
Show worked solution
Keep A as confirmed success and B as a confirmed individual failure under the stated evidence. C remains uncertain until supported results or scoped state reconciliation establish its outcome; retain its source identity.
Check your solution
- A and B retain their known categories.
- C remains uncertain until reconciled.
12. A batch increments a counter from 10; its response is lost. Compare a blind retry with a durable operation-ID check and identify the intended result.
Show hint
The first increment may already have applied.
Show worked solution
One application should yield 11; a blind second application can yield 12. Reconcile the stable operation ID and its recorded postcondition before retrying, and escalate if the outcome remains uncertain.
Check your solution
- The intended count is 11, not 12.
- Operation identity and postcondition are checked before retry.
13. Manifest indices 0, 1, 2 map to source IDs A, B, C. A collection bulk write error reports index 2. Identify the source item and repair-batch requirement.
Show hint
Use the original zero-based mapping.
Show worked solution
Index 2 maps to C. Preserve that original source identity when making a repair batch, even if C becomes position 0 in the smaller retry list, so subsequent errors can be traced correctly.
Check your solution
- The original failed source item is C.
- The repair batch retains the original mapping.
14. An unordered batch has A valid, B duplicate, C invalid and D valid. Under no interruption, design a reconciliation table.
Show hint
Separate successful items from different failure causes.
Show worked solution
Record A and D as successful under the stated assumptions, B as duplicate-key failure and C as validation failure. Preserve their source IDs and use different remediation for the two failures.
Check your solution
- A and D are recorded separately from failures.
- B and C retain distinct failure causes.
15. A deleteOne matches zero documents, but the source manifest requires deleting one. Explain the business consequence and next evidence.
Show hint
A zero delete can be a normal technical result.
Show worked solution
The database may report no deletion without a write exception, yet the manifest requirement is unmet. Inspect the target identity and expected state before deciding whether it was already deleted or the filter is wrong.
Check your solution
- The required one deletion is not confirmed.
- The identity and prior state are investigated.
16. Two successful ordered updates target the same document, one setting a and one setting b. Explain why two operations do not imply two distinct documents.
Show hint
Count operation identities and document identities separately.
Show worked solution
Both updates can succeed against the same document ID, so there are two operations but one distinct affected document. Reconcile at the grain required by the report rather than treating operation count as entity count.
Check your solution
- The successful operation count can be 2.
- The distinct document count can be 1.
17. A bulk call succeeds inside a transaction, then commit is aborted. What must a report say about the participating writes?
Show hint
Intermediate operation success is not the final transaction outcome.
Show worked solution
The participating writes do not commit when the transaction aborts. Check the actual transaction outcome and session participation rather than applying outside-transaction partial-success assumptions to the intermediate bulk result.
Check your solution
- The transaction outcome is abort.
- The participating changes do not commit.
18. A batch manifest has 12 items: 6 confirmed successes, 2 failures, 1 known unattempted and 2 uncertain. Find the accounting gap.
Show hint
Sum mutually exclusive categories.
Show worked solution
The categories total 11, leaving one source item unclassified. Find its original identity and determine whether evidence supports success, failure, unattempted or uncertain status before declaring the reconciliation complete.
Check your solution
- The known categories sum to 11.
- One manifest item remains unclassified.
19. A team migrates from collection bulkWrite to client-level multi-namespace bulk in MongoDB 8.0. State the compatibility and result-handling review.
Show hint
The server feature and driver API are separate version contracts.
Show worked solution
Verify that the installed driver supports the client-level API with the target server, then implement its documented result and error types. Do not assume collection-level error fields or namespace scope are identical.
Check your solution
- Server and driver compatibility are verified.
- Result and error handling follows the selected API.
20. Design an acceptance fixture for partial bulk outcomes and uncertain retry.
Show hint
Include one known write error and a separate lost-response scenario.
Show worked solution
Use independent operations with a mid-list duplicate in both ordered and unordered modes, plus a separate non-idempotent increment whose response is lost. Verify source identity, stored postconditions and bounded reconciliation rather than resubmitting blindly.
Check your solution
- The fixture distinguishes ordered and unordered error behavior.
- The lost-response path checks idempotency and actual state.
Key takeaways
- A bulk batch can have partial success.
- Ordered and unordered modes have different error and ordering behavior.
- Reconcile actual outcomes before retrying.
- A bulk write outside a transaction is not automatically atomic as a batch.
- Unordered processing can continue after an individual error without list-order guarantees.
- A lost response does not prove that no write occurred.